並感謝您傾聽...併爲我的糟糕英語感到抱歉。 我有一個簡單的Python腳本的問題,我不知道如何粉碎我的頭。帶參數,類和tkinter的Python noob
這就是代碼。是非常簡單和無用(我正在學習python,但我的編程技能是embarissing)。
import tkinter as tk
class hello:
button_state = [0,0,0,0,0,0,0,0,0]
def __init__(self):
self.root = tk.Tk()
self.button = tk.Button(self.root, text=self.button_state[0],
command=self.check(0))
self.button.pack()
def check(self,x):
if x == 0:
self.button_state[x] = 1
self.button.config(text=self.button_state[x])
app = hello()
app.root.mainloop()
和錯誤:
AttributeError: 'hello' object has no attribute 'button'
我不知道爲什麼,如果我使用標籤的問題不存在」。我嘗試和嘗試,我認爲錯誤是在參數調用按鈕命令?
感謝提前:)