所以这就是代码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"
我不确定为什么我会收到这个错误,如果有人能够发现问题,我将非常感激。
答案 0 :(得分:1)
showQuestion()
正在尝试修改窗口小部件,但是在根窗口被销毁后调用它(例如:在mainloop()
之后返回,这只有在根窗口被销毁时才会发生)。当根窗口被销毁时,所有其他小部件也会被销毁。