使用tkinter时的TypeError(python)

时间:2013-08-18 14:08:13

标签: python-3.x tkinter

我写了一个测试程序来模拟我的错误。这是代码:

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。

1 个答案:

答案 0 :(得分:2)

您没有创建匹配对象。 (缺少()

替换以下行:

    self.match = match

    self.match = match()