下面的代碼:Python的類型錯誤:take_one()缺少必需的1位置參數: '狀態'
from tkinter import *
class Main_content:
def take_one(self, state):
state = state - 1
return self.state
def take_two(self, state):
state = state - 2
return self.state
def __init__(self, master, state):
frame = Frame(master)
frame.pack()
self.label_status = Label(frame, text = "Coins left: " + str(state))
self.label_status.pack()
self.label_status = Label(frame, text = "Player " + str(player) + " turn's")
self.label_status.pack()
self.pak_een = Button(frame, text="Take 1 coin", command=self.take_one)
self.pak_een.pack()
self.pak_twee = Button(frame, text="Take 2 coins", command=self.take_two)
self.pak_twee.pack()
root = Tk()
player = 1
state = 21
b = Main_content(root, state)
root.mainloop()
的錯誤是:
Traceback (most recent call last):
File "C:\Users\Freddie\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
TypeError: take_two() missing 1 required positional argument: 'state'
我新,所以我想不通我做錯了什麼。我不知道這意味着什麼。
按鈕不會nd事件或其他參數給他們的命令處理程序。你的論點「國家」應該從哪裏來? – Marvo
@DeepSpace爲什麼要刪除traceback標籤和python3標籤?有沒有用? – Stargateur
@Stargateur這個錯誤不是Python3特有的,跟蹤標記與這個問題無關。 – DeepSpace