0

I don't know why this is giving me an attribute error. I want my blah() function to shuffle the cards. I'm calling the builtin function shuffle() from random.

Error:

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

Here's the code snippet:

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)
2
  • Can you please add the part of the code where Button is defined and/or imported? Commented Apr 5, 2015 at 7:52
  • Button is a class in tkinter. Commented Apr 5, 2015 at 18:14

1 Answer 1

2

shuffle is the name of the function in random. However, it's also the name of the Button. Change the Button's name to something like shuffle_button and you should be fine.

Sign up to request clarification or add additional context in comments.

2 Comments

You are pointing out an other problem in the code. But the the error message indicates that Button has also been overloaded.
It's saying that shuffle, an instance of Button, doesn't have a defined behavior for being called as a function. The error is appearing in blah() with shuffle(cards). The Button called shuffle isn't a function that can be called with an argument of cards; it's just a Button. A new name that doesn't override shuffle should fix the issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.