Reputation: 23
I am trying to use a button to cycle through a list. It works once, but then doesn't respond to any other presses.
cards = ["2 of Diamonds", "3 of Diamonds"] #etc (don't want it to be too long)
current = 0
def next():
current=+1
print("\"current\" variable value: ", current)
card.config(text=cards[current])
next = Button(text="⇛", command=next, fg="White", bg="Red", activebackground="#8b0000", activeforeground="White", relief=GROOVE).grid(column=2, row=1)
Any suggestions?
Upvotes: 1
Views: 95
Reputation: 385940
current
is a local variable that you initialize to 1
each time the function is called.
You need to do two things:
current
as global+=
rather than =+
)Example:
def next():
global current
current += 1
...
Upvotes: 2