阙辉

3.4、设置为密码输入框

# show:用来作为显示的字符
from Tkinter import *
root = Tk()
e = StringVar()
entry = Entry(root,textvariable = e)
e.set('input your text here')
entry.pack()
#使用*来显示输入的内容,如果喜欢可以改为其它字符
entry['show'] = '*'
#分别使用*#$显示输入的文本内容
for mask in ['*','#','$']:
e = StringVar()
entry = Entry(root,textvariable = e)
e.set('password')
entry.pack()
entry['show'] = mask
root.mainloop()
#将 Entry 作为一个密码输入框来使用,即不显示用户输入的内容值,用特定符号代替。使
用用属性 show 来指定。

代码

from tkinter import *
quehui = Tk()
e = StringVar()
quehui_1 = Entry(quehui,
textvariable = e)
e.set("请在这输入文本")

quehui_1.pack()
quehui_1['show'] = '*'

for mask in ['*','#','$']:
e = StringVar()
quehui_1 = Entry(quehui,
textvariable = e)
e.set('password')
quehui_1.pack()
quehui_1['show'] = mask

quehui.mainloop()

 

posted on 2018-06-25 10:50  真辉辉  阅读(213)  评论(0)    收藏  举报

导航