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