2016-10-30 61 views
1

所以這是代碼蟒蛇似乎並沒有太高興與我有關:TclError在Tkinter的

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" 

我我不知道爲什麼我會收到這個錯誤,非常感謝,如果有人能夠確定問題。

回答

1

showQuestion()試圖修改一個小部件,但根窗口已被破壞後,它被調用(如:後mainloop()回報,當根窗口已被銷燬,只發生)。當根窗口被銷燬時,所有其他小部件也被銷燬。

+0

你是絕對的明星,布萊恩,謝謝你。這消失了,並解決了它,並解決了我遇到的幾個問題! – Roxy