【问题标题】:Python Tkinter : AttributeError: Button instance has no __call__ methodPython Tkinter:AttributeError:按钮实例没有__call__方法
【发布时间】:2015-04-05 05:44:51
【问题描述】:

我不知道为什么这会给我一个属性错误。我想要我的blah() 函数来洗牌。我正在从random 调用内置函数shuffle()

错误:

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

这里是sn-p的代码:

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)

【问题讨论】:

  • 您能否添加定义和/或导入Button 的代码部分?
  • Buttontkinter 中的一个类。

标签: python button tkinter


【解决方案1】:

shufflerandom 中的函数名称。但是,它也是Button 的名称。将Button 的名称更改为shuffle_button 之类的名称就可以了。

【讨论】:

  • 您指出了代码中的另一个问题。但是错误信息表明 Button 也已被重载。
  • 意思是shuffleButton 的一个实例,它没有被定义为函数的行为。错误出现在blah()shuffle(cards)。名为shuffleButton 不是可以使用cards 参数调用的函数;它只是一个Button。不覆盖 shuffle 的新名称应该可以解决此问题。
猜你喜欢
  • 2018-02-23
  • 2013-07-22
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 2012-07-04
  • 1970-01-01
  • 2015-04-07
相关资源
最近更新 更多