【发布时间】:2021-03-30 16:17:50
【问题描述】:
我正在使用 Tkinter 制作一个 GUI,其中开始菜单为用户提供了在学生帐户和管理员帐户之间切换的选项。对于学生来说,需要一个姓名,而对于管理员来说,则需要一个密码,该密码可以输入到相同的输入框。密码需要用星号 (*) 隐藏,因为这对于名称输入不是必需的。
从学生帐户切换到管理员帐户后,下次我想将输入框更改回学生帐户的正常文本视图。 这是我的代码的精简版。
admin = False
def switchUser():
global admin
if admin:
admin = False
userEntry.config(show='*')
titleLabel.config(text='Enter the password')
else:
admin = True
#code to switch back to default text view in entry box
titleLabel.config(text='Enter your name')
titleLabel = Label(startMenu, text='Enter your name')
userEntry = Entry(startMenu)
adminButton = (startMenu, text='Admin????', command=switchUser)
【问题讨论】:
-
<tkinter.Entry>.config(show="") -
另外我认为你在
(startMenu, text='Admin????', command=switchUser)之前的最后一行缺少Button
标签: python tkinter tkinter-entry