2017-06-17 1 views
0

Yat-il un moyen de convertir le texte en points lors de la saisie dans python 3 Terminal.
mon code est:Comment afficher du texte lors de la saisie en tant que points dans un terminal Python?

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

Je sais que le module getpass .Mais il ne fonctionne pas dans le Terminal, il avertit:

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

Si elle peut fonctionner sans avertissement et cacher le texte, S'il vous plaît dîtes-moi.
Y at-il somthing otherway comme:

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

Je crée un script qui demande à l'utilisateur de donner mot de passe, mais il semble mal si mot de passe est montré lors de la frappe.
Je suis ici avec l'espoir que vous puissiez m'aider.
Si vous voulez plus d'informations, je suis prêt à vous fournir.
Merci ....

+0

Quel terminal et OS? – mx0

+0

Copie possible de ["GetPassWarning: Impossible de contrôler l'écho sur le terminal" lors de l'exécution de IDLE] (https://stackoverflow.com/questions/38878741/getpasswarning-can-not-control-echo-on-the-terminal- when-running-from-idle) – mx0

+0

Je suis sur Windows. Vérifiez cette [Image] (https://postimg.org/image/f86ngmmez/f97b4fac/). –

Répondre

0

L'utilisation d'un mot de passe avec tkinter séparément est une mauvaise idée.
J'ai créé ce celui dans lequel il a le nom d'utilisateur et mot de passe, sauf que le mot de passe:

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() 

espère que ce sera utile pour vous.
Getpass est pas IDLE

0

Vous ne pouvez pas utiliser getpass à Python IDLE.

également essayer des choses comme la redirection stdout les causes shell restart à l'intérieur IDLE:

import sys 
import os 
import getpass 

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

== RESTART: Shell == 

Peut-être que vous pouvez utiliser tkinter fenêtre de dialogue pour inviter l'utilisateur pour le mot de passe:

# 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='*') 

Il suffit de l'enregistrer en fonction:

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

et d'utiliser get_pass() au lieu de getpass().

+0

Cochez cette [erreur] (https://postimg.org/image/e2gbi0ep1/). –

+0

@mini J'ai mis à jour le code pour travailler avec Python 3.5 et 3.6. – mx0

+0

Son parfait mais pouvez-vous convertir tout le code à une petite ligne illisible? –