我正在尝试使用Tkinter编写登录窗口,但我无法以星号格式隐藏密码文本.这意味着密码输入是纯文本,必须避免.知道怎么做吗?
Fed*_*oca 64
快速谷歌搜索产生了这一点
widget = Entry(parent, show="*", width=15)
Run Code Online (Sandbox Code Playgroud)
其中widget是文本字段,parent是父窗口小部件(窗口,框架,等等),show是要回显的字符(即显示的字符Entry),width是窗口小部件的宽度.
Shu*_*ule 21
如果您不想创建全新的Entry小部件,则可以执行以下操作:
myEntry.config(show="*");
Run Code Online (Sandbox Code Playgroud)
要使其恢复正常,请执行以下操作:
myEntry.config(show="");
Run Code Online (Sandbox Code Playgroud)
我通过检查前面的答案,并使用Python解释器中的帮助功能(例如帮助(tkinter.Entry)导入后(从扫描那里的文档)发现了这一点.我承认我只是想知道如何让它恢复正常.
小智 7
widget-name = Entry(parent,show="*")
Run Code Online (Sandbox Code Playgroud)
您还可以使用项目符号:
bullet = "\u2022" #specifies bullet character
widget-name = Entry(parent,show=bullet)#shows the character bullet
Run Code Online (Sandbox Code Playgroud)
这是一个小的,非常简单的演示应用程序,使用Tkinter隐藏和获取密码.
#Python 3.4 (For 2.7 change tkinter to Tkinter)
from tkinter import *
def show():
p = password.get() #get password from entry
print(p)
app = Tk()
password = StringVar() #Password variable
passEntry = Entry(app, textvariable=password, show='*').pack()
submit = Button(app, text='Show Console',command=show).pack()
app.mainloop()
Run Code Online (Sandbox Code Playgroud)
希望有所帮助!
| 归档时间: |
|
| 查看次数: |
47835 次 |
| 最近记录: |