python - TKinter 属性 Simpledialog 错误
问题描述
我目前正在尝试使用 Python 3.6 中的 tkinter 模块(通过 Spyder)编写一些基本的用户输入框。我可以确认模块已加载,并且出现了选择 simpledialog 的选项,但我不断收到以下错误:
AttributeError:模块“tkinter”没有属性“simpledialog”
我试图寻找其他选项,但其他用户输入选项似乎不适用于我的 Python 界面。它要么崩溃,要么数据结构不正确。
有趣的是,在过去,我在 Python 中做过类似的事情,没有出现任何错误,但这一直是这个特定的编程部分。
import tkinter as tk
import pyodbc as py
py.pooling = False
## INPUT YOUR USER ID AND PASSWORD AND DECLARE YOUR CONNECTION
## THE DIALOG BOXES MAY POP OPEN ON ANOTHER SCREEN
## THE PASSWORD INPUT IS MASKED AND WILL NOT SHOW IN THE
## VARIABLE EXPLORER
ID = tk.simpledialog.askstring("Please input your username.","Username: ")
PW = tk.simpledialog.askstring("Please input your password.",
"Password: ", show='*')
CONN = tk.simpledialog.askstring("Please input your connection.",
"Connection: ")
我的预期结果是会出现一个弹出窗口,并且我将能够获取我需要的用户信息,以保持与我正在使用的服务器的稳定连接。
提前感谢您的建议!
解决方案
simpledialog
不在tkinter
但在tkinter.simpledialog
,你必须导入它
import tkinter as tk
import tkinter.simpledialog
root = tk.Tk() # create main window
#root.iconify() # minimize main window
root.withdraw() # hide main window
answer = tkinter.simpledialog.askstring("Question", 'Your name:')
print(answer)
#root.destroy() # should work without it
#root.mainloop() # should work without it
推荐阅读
- c# - C# 使用数组切换命名空间
- javascript - 我的不和谐测试机器人返回“您无权使用该命令”,即使我的角色频道上明确有它
- c# - 如何在 DbContextOptions 中执行依赖注入
- c++ - 如果第一个参数小于阈值,则跳过函数参数计算
- android - MITMProxy 7.0.4 + Android 模拟器 AVD 30
- python - PYTHON 的部分 ROC 曲线的 P 值
- android - 可绘制的单选按钮对 state_checked 没有反应
- python - 使用python将大型xlsx拆分为多个csv文件
- reactjs - 通用 TS 在这种情况下如何工作
- flutter - useTabController 索引永远不会改变