Issue
Currently I want to try to wait for a condition say x>5 to occur then when that happens I want to change the image for a label, wait for 10 seconds, then return to the original image but I keep getting different errors.
Mainly, I'm wondering how to change a label's image then change it back. I want to change my image from a photo to a gif then back to the photo.
How can I accomplish this without errors?
Solution
In a nutshell:
the_label.configure(image=the_first_image)
the_label.after(5000, lambda: the_label.configure(image=the_second_image))
Of course, in practice it's slightly more complicated since you have to create the images, worry about if this code is called twice in less than 5 seconds, etc. But the general idea is the same: use after
to schedule a command to change it back after a given number of milliseconds.
Note: you don't have to use lambda. You can call a predefined function, or you could use functools.partial. There are plenty of examples here on stackoverflow.
Answered By - Bryan Oakley Answer Checked By - Robin (PHPFixing Admin)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.