2

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

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。

4

1 回答 1

2

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

替换以下行:

    self.match = match

    self.match = match()
于 2013-08-18T14:09:39.747 回答