首页 > 解决方案 > tkinter Entry中的'show'参数设置为show="*"后如何设置为默认值?

问题描述

我正在使用 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)

标签: pythontkintertkinter-entry

解决方案


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

userEntry.configure(show="")

推荐阅读