python - 创建 tkinter.Toplevel() 对象时出现“str”对象不可调用错误
问题描述
在这里的这段代码中,我收到以下错误。我已经搜索了所有内容,但仍然不知道为什么会这样。基本上,我的菜单栏中有一个返回主页的选项,它应该会弹出一个提示,询问用户是否确定他们想要离开而不提交。
self.optionsMenu = tkinter.Menu(self, tearoff=0) # creates 'Options' cascade
self.optionsMenu.add_command(label="Home", command=self.parent.returnHome)
...
def returnHome(self, *args):
self.page = index.AdminApplication(self.parent)
self.confirmLeave()
def confirmLeave(self, *args):
confirmPopup = tkinter.Toplevel(self.parent)
confirmPopup.title("Confirm Leave Page")
confirmPopup.tkraise(self.parent)
question = tkinter.Label(confirmPopup, text="Are you sure you want to leave without submitting your bracket?", font=('Helvetica', '10'))
question.grid(row=0, column=0, sticky=tkinter.N+tkinter.S+tkinter.W+tkinter.E)
leave = tkinter.Button(confirmPopup, text="Leave", height=0, width=100, command=self.changeRootSettings(self.page))
leave.grid(row=1, column=0)
cancel = tkinter.Button(confirmPopup, text="Cancel", height=0, width=100, command=confirmPopup.destroy())
cancel.grid(row=1, column=1)
confirmPopup.focus_force()
错误:
$ C:/Users/student/AppData/Local/Programs/Python/Python37-32/python.exe c:/Users/student/Documents/BracketsTool/index.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\student\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "c:\Users\student\Documents\BracketsTool\CreateBracket.py", line 37, in returnHome
self.confirmLeave()
File "c:\Users\student\Documents\BracketsTool\CreateBracket.py", line 23, in confirmLeave
confirmPopup = tkinter.Toplevel(self.parent)
File "C:\Users\student\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 2345, in __init__
self.title(root.title())
TypeError: 'str' object is not callable
旁注:我知道代码实际上还不会做我想做的事,但我不想尝试任何事情,因为如果不先正确拉起窗口,我就无法测试它。
解决方案
推荐阅读
- php - 允许用户每天只在数据库中插入/发布一次
- python - 尝试使用 setter 为正在存储的字符串添加标签
- php - PHP - 如何缓存从 AWS KMS Parameter Store 检索的数据库凭证
- .net - 使用 Inno Setup 安装期间报告安装的 .NET Framework 版本
- javascript - 如何使用纯javascript显示来自api的图片
- ruby - Beginner Ruby Programmer - 在练习题上打印错误
- python - Python - 循环加速 - 大型数据集
- node.js - 在 session.withTransaction 中返回一个节点 js 响应
- python - 'builtin_function_or_method' 对象在 Python 上不可下标
- null - 地图接口方法。首先要做的事情<我正在使用hashMap并遇到了在控制台中获取空值的问题