python - 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)
解决方案
您可以将show
选项设置为空字符串。
userEntry.configure(show="")
推荐阅读
- javascript - 如何将一组数组(字符串格式)推送到数组中?
- oracle - 流水线函数在编译时给出“PLS-00630”错误
- python - 将 2 .CSV 与未知数量的列和名称进行比较
- r - 在时间序列中创建平稳性的问题
- lda - 如何获得两个模型的主题连贯性分数,然后将其用于比较?
- mysql - 如果 MySQL 数据库中不存在另一个对象,如何创建 SQL 查询来保存对象?
- nuxt.js - 在根路由 NuxtJS 中使用 get param
- php - 如何在php中添加.docx的下载链接
- ios - 本地化自然格式的 API 数据列表
- c++ - 使用选项 -fstack-usage 和 -fdump-rtl-expand 匹配 g++ 生成的文件中的标识符