gpt4 book ai didi

python - tkinter 中的 Tcl 错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:01:01 25 4
gpt4 key购买 nike

所以这是 python 似乎对我不太满意的代码:

def checkAnswer(self, clickedButton):
self.valueOne = self.itemOne[self.component]
self.valueTwo = self.itemTwo[self.component]

if clickedButton == 'left':
if self.valueOne >= self.valueTwo:
tkinter.messagebox.showinfo('Smart Cookie!', 'That\'s correct!')

else:
tkinter.messagebox.showerror('Oh No!', 'That\'s incorrect!')

elif clickedButton == 'middle':
if self.valueOne - (self.valueOne * 0.1) <= self.valueTwo <= self.valueOne + (self.valueOne * 0.1) and self.valueTwo - (itemTwoComp * 0.1) <= self.valueTwo <= self.valueTwo + (self.valueTwo * 0.1):
tkinter.messagebox.showinfo('Smart Cookie!', 'That\'s correct!')

else:
tkinter.messagebox.showerror('Oh No!', 'That\'s incorrect!')

elif clickedButton == 'right':
if self.valueTwo >= self.valueOne:
tkinter.messagebox.showinfo('Smart Cookie!', 'That\'s correct!')

else:
tkinter.messagebox.showerror('Oh No!', 'That\'s incorrect!')


showQuestion()


tkinter.mainloop()
showQuestion()

gui = ProgramGUI()

这是我收到的错误:

Traceback (most recent call last):
File "C:\Assignments\Assignment 2\FIddle.py", line 101, in <module>
gui = ProgramGUI()
File "C:\Assignments\Assignment 2\FIddle.py", line 99, in __init__
showQuestion()
File "C:\Assignments\Assignment 2\FIddle.py", line 60, in showQuestion
self.lab11.configure(text = self.itemList[0]['Name'])
File "C:\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1330, in configure
return self._configure('configure', cnf, kw)
File "C:\AppData\Local\Programs\Python\Python35\lib\tkinter\__init__.py", line 1321, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".2531617022640.2531617023144"

我根本不确定为什么会收到此错误,如果有人能够找出问题所在,我将非常感激。

最佳答案

showQuestion() 正在尝试修改一个小部件,但它是在根窗口被销毁后调用的(例如:在 mainloop() 返回后,这只当根窗口被破坏时发生)。当根窗口被销毁时,所有其他小部件也会被销毁。

关于python - tkinter 中的 Tcl 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40331504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com