2013-08-18 85 views
2

我寫了一個測試程序來模擬我的錯誤。 Here's代碼:使用tkinter時的TypeError(python)

from random import * 
from tkinter import * 

class match: 
    def __init__(self): 
     self.players = 4*[None] 

    def commandos(self): 
     print("show commands:") 
     print("now commands for you!") 

    def choice(self, choose): 
     print("No choice") 

class Application(Frame): 

    def __init__(self, master, match): 
     Frame.__init__(self, master) 
     self.grid() 
     self.create_widgets() 
     self.match = match 
     self.match.commandos() 

    def create_widgets(self): 
     self.submit_button = Button(self, text = "Submit", command = self.button_click) 
     self.submit_button.grid(row = 2, column = 0, sticky = W) 

     self.entry = Entry(self) 
     self.entry.grid(row = 1, column = 1, sticky = W) 

    def button_click(self):   
     choose = self.entry.get() 
     while choose != 'S': 
      self.match.choice(choose) 
      choose = input() 

root = Tk() 
root.title("StackQuestion") 
root.geometry("250x150") 
app = Application(root, match) 

root.mainloop() 

當我運行它,我得到這個錯誤:

Traceback (most recent call last): 
    File "H:/Dropbox/Programmering/Python/stachquestion.py", line 40, in <module> 
    app = Application(root, match) 
    File "H:/Dropbox/Programmering/Python/stachquestion.py", line 22, in __init__ 
    self.match.commandos() 
TypeError: commandos() missing 1 required positional argument: 'self' 

我該如何解決這個問題?我需要解決這個問題,所以我可以在我的網球程序中使用GUI。

回答

2

您沒有創建匹配對象。 (缺少()

替換以下行:

self.match = match 

self.match = match() 
+0

我感覺自己像是缺少的白癡。 –

相關問題