【问题标题】:How to set the 'show' parameter in tkinter Entry to default value after it has been set to show="*"?tkinter Entry中的'show'参数设置为show="*"后如何设置为默认值?
【发布时间】: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


【解决方案1】:

您可以将show 选项设置为空字符串。

userEntry.configure(show="")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-07
    • 1970-01-01
    • 2013-01-01
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    相关资源
    最近更新 更多