I'm a beginner programmer and I'm trying to learn how to make code run continuously in tkinter.
My aim for testing is just to get a label to change colour every 2 seconds regardless of input.
I understand I can use the following format (with lbl
initialised as a Label)
def switch():
if lbl.cget('bg') == 'blue':
lbl.config(bg='black')
else:
lbl.config(bg='blue')
lbl.after(2000, switch)
This works fine. However, I want to be able to call switch
for any label rather than just lbl
specifically.
If I try the below I immediately get a recursion depth error
def switch(i):
if i.cget('bg') == 'blue':
i.config(bg='black')
else:
i.config(bg='blue')
i.after(2000, switch(i))
lbl.after(2000, switch(lbl))
I'm not sure why this is a the case, or what I could do to get round it so any help would be appreciated!!!