Skip to main content
 首页 » 编程设计

python之在python中隐藏密码输入输入

2025年05月04日15zdz8207

我正在尝试制作一个小登录程序。但我不确定是否有办法在您输入密码时用星号替换“密码”。这是我的代码:

from tkinter import * 
 
def callback(): 
print("hi") 
 
top = Tk() 
L1 = Label(top, text="User Name") 
L1.grid(row=0, column=0) 
E1 = Entry(top, bd = 5) 
E1.grid(row=0, column=1) 
 
L1 = Label(top, text="Password") 
L1.grid(row=1, column=0) 
E1 = Entry(top, bd = 5) 
E1.grid(row=1, column=1) 
 
MyButton1 = Button(top, text="Submit", width=10, command=callback) 
MyButton1.grid(row=3, column=1) 
 
top.mainloop() 

请您参考如下方法:

使用 show="*" 选项。例如

E1 = Entry(top, bd = 5, show="*")