0

Is there Any way to convert Text to Dots while Inputting In python 3 Terminal.
my Code is:

[........
user = input('Enter Your UserName:')
pass = input('Enter Your Password:')
........]  

I know the Module getpass.But it don't work in Terminal , It gives warning:

Warning (from warnings module):
return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.  

If it can work without warning and hide text,Please tell me.
Is there any Otherway somthing like:

import sys
shell = sys.stdout.shell
shell.show input as '0';
....

I am creating a script that asks the user to give Password but it looks bad if Password is being showed while typing.
I am here with a hope that you may help me.
If you want more information,I am ready to provide to you.
Thanks....

4
  • What terminal and OS? Commented Jun 17, 2017 at 12:05
  • Possible duplicate of "GetPassWarning: Can not control echo on the terminal" when running from IDLE Commented Jun 17, 2017 at 12:06
  • I am on windows.Check this Image. Commented Jun 17, 2017 at 12:09
  • Any other way Please? Commented Jun 17, 2017 at 12:11

2 Answers 2

1

You can't use getpass inside Python IDLE.

Also trying things like redirecting stdout causes shell restart inside IDLE:

import sys
import os
import getpass

sys.stdout = os.devnull
getpass.getpass()

== RESTART: Shell ==

Maybe you can use tkinter dialog window to prompt user for password:

# import tkinter (a crossplatform GUI)
import tkinter

# import a simple dialog form with a label and a button
# so you don't have to build one yourself
import tkinter.simpledialog

# create an empty main window for GUI,
# without it you will get an error:
# AttributeError: 'NoneType' object has no attribute 'winfo_viewable'
tk_root = tkinter.Tk()

# you don't really need to show it, so hide it immediately
tk_root.withdraw()

# create a dialog window with title 'Password'
# and a text label 'Enter Your Password:'
# also hide typed password with *
passwd = tkinter.simpledialog.askstring('Password','Enter Your Password:', show='*')

Just save it as a function:

def get_pass():
    import tkinter
    import tkinter.simpledialog
    tk_root = tkinter.Tk()
    tk_root.withdraw()
    return tkinter.simpledialog.askstring('Password','Enter Your Password:', show='*')

and use get_pass() instead of getpass().

Sign up to request clarification or add additional context in comments.

4 Comments

@mini I've updated code to work with Python 3.5 & 3.6.
Its perfect but can you convert all the code to one unreadable small line?
@mini I've added some comments to that snippet. What do you mean by "convert all the code to one unreadable small line"?
We can Also Make It Into A module.Write The Function get_pass() in pypass.py .Now Place It In Lib folder in python36-32 .Now You can use It Like: import pypass pypass.get_pass()and it will work.Also In 1 line.
0

Using password input with tkinter separately is a bad idea.
I created this one in which it has username and password except password only:

from tkinter import * #(tkinter (A cross-platform GUI)

top = Tk()
def callback(): #what to do after button(Submit) pressed
    print(E2.get()) #printing first input
    print(E1.get()) #printing second input
    top.destroy() #exiting tkinter
top.title('Login')
L1 = Label(top, text="User Name")
L1.grid(row=0, column=0) #setting up position for user name field
E2 = Entry(top, bd = 5)
E2.grid(row=0, column=1)

L1 = Label(top, text="Password")  # text for second name,currently Password
L1.grid(row=1, column=0) #setting up position for password field
E1 = Entry(top, bd = 5,show='*') #hidding the text with *
E1.grid(row=1, column=1)
MyButton1 = Button(top, text="Submit", width=10, command=callback) # button named submit
# 'command=callback ' the command you want to do|we have created a function callback

MyButton1.grid(row=3, column=1) # position for button

top.mainloop()

Hope It will be helpful for you.
Getpass is not for IDLE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.