Sequencing images using tkinter?

Peter Otten __peter__ at web.de
Sat Aug 30 17:14:10 EDT 2014


theteacher.info at gmail.com wrote:

> How do you exit from this function?
> 
> def next_image():
>     myLabel.config(image=random.choice(monster_images))
>     # tell tkinter to invoke next_image() again after 200 miliseconds

You misunderstand. The problem with the function is not that it doesn't 
exit, it's just that with

>     root.after(200, next_image)

it schedules itself to be reinvoked by tkinter after 200 seconds. If you 
want to limit that to 10 times instead of indefinitely you can introduce a 
counter:

n = 10
def next_image():
    global n

    myLabel.config(image=random.choice(monster_images))
    n -= 1
    if n > 0:
        root.after(200, next_image)
              






More information about the Python-list mailing list