2017-04-12 77 views
0

您好我一直在爲這個項目做一個化學A水平測驗的學生。 我做了一組對應於每個TK幀間的類。有幾類從主要問題繼承的問題。 我不知道爲什麼我收到此錯誤,爲什麼我的代碼不工作:Tk面向對象的編程

錯誤:

Traceback (most recent call last): 
File "/Users/ammarhusain/Desktop/Computing Project/Ammar Chemistry Program 
FINAL.py", line 3376, in <module> 
    quiz = Main() 
    File "/Users/ammarhusain/Desktop/Computing Project/Ammar Chemistry Program FINAL.py", line 3360, in __init__ 
    frame = F(container, self) 
    File "/Users/ammarhusain/Desktop/Computing Project/Ammar Chemistry Program FINAL.py", line 1167, in __init__ 
    tk.Frame.__init__(self, parent,controller) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2583, in __init__ 
    Widget.__init__(self, master, 'frame', cnf, {}, extra) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2138, in __init__ 
    (widgetName, self._w) + extra + self._options(cnf)) 
_tkinter.TclError: unknown option "-use" 

主要代碼:

class Main(tk.Tk): 
    def __init__(self, *args, **kwargs): 
     tk.Tk.__init__(self, *args, **kwargs) 



     container = tk.Frame(self) 
     container.pack(side="top", fill="both", expand=True) 
     container.grid_rowconfigure(0, weight=1) 
     container.grid_columnconfigure(0, weight=1) 
     self.frames = {} 


     for F in (STUDENTLOGINPAGE,STAFFLOGINPAGE,STARTPAGE,STAGE1,STAGE2,STAGE3,STAGE4,STAGE5,LEADERBOARDPAGE): 

      frame = F(container, self) 

      self.frames[F] = frame 

      frame.grid(row = 0, column = 0, sticky = "nsew") 

      self.show_frame(STUDENTLOGINPAGE) 
      if self.frames == []: 
       print ("Error in loading program") 
#This class inherits from Tk class within module of Tk Inter 
       #This basically displays each page in turn from the List 

    def show_frame(self, cont): 
     frame = self.frames[cont] 
     frame.tkraise() 

quiz = Main() 
quiz.mainloop() 
+0

@eyllanesc:請不要引用格式回溯。這不是更具可讀性,而且您正在積極破壞問題來源中的重要間距信息。 – user2357112

+0

錯誤來自您未發佈的頁面類之一 - 我無法分辨哪一個,但它看起來是在第1167行(這是跟蹤您的源代碼的最後一行,而是比Python庫)。你有一個'__init__',它將3個參數傳遞給繼承的'Frame .__ init__',儘管在那裏只有兩個位置參數是有意義的。 – jasonharper

回答

0

您需要從該行刪除,controller

tk.Frame.__init__(self, parent,controller) 

controller是爲u參數nique的子類,並不是在基類中支持的東西。