2015-04-05 58 views
0

我不知道爲什麼這給我一個屬性錯誤。我希望我的blah()功能可以洗牌。我正在從random調用內置函數shuffle()Python Tkinter:AttributeError:按鈕實例沒有__call__方法

錯誤:

Exception in Tkinter callback 
Traceback (most recent call last): 
    File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489, in __call__ 
    return self.func(*args) 
    File "gui1.py", line 105, in blah 
    shuffle(cards) 
AttributeError: Button instance has no __call__ method 

下面的代碼片段:

def blah(): 
    global card_count 
    global path 
    shuffle(cards) 
    card_count = 0 
    path = generate_paths(cards) 
    print "Cards Shuffled" 

shuffle = Button(frame_buttons, text = "SHUFFLE",height = 2, width = 10,command =blah) 
shuffle.grid(row = 2 , padx = 40, pady = 40) 
+0

您可以添加「Button」被定義和/或導入的代碼部分嗎? – 2015-04-05 07:52:32

+0

'Button'是'tkinter'中的一個類。 – TigerhawkT3 2015-04-05 18:14:34

回答

2

shufflerandom函數的名稱。但是,它也是Button的名稱。把Button的名字改成shuffle_button,你應該沒問題。

+0

您正在指出代碼中的其他問題。但是,錯誤消息指示Button也被重載。 – 2015-04-05 07:51:40

+1

這就是說''shuffle','Button'的一個實例沒有被定義爲一個函數的行爲。錯誤出現在''blah()'with'shuffle(cards)'中。被稱爲'shuffle'的Button不是一個可以用'cards'參數調用的函數。它只是一個'Button'。不覆蓋'shuffle'的新名稱可以解決問題。 – TigerhawkT3 2015-04-05 08:06:17