Aug-09-2021, 06:08 PM
(This post was last modified: Aug-09-2021, 06:08 PM by deanhystad.)
I do not understand what you are trying to do. Your example is nothing like what you claim. Are you adding images or moving images, or are you changing images to give the impression of motion? What kind of program are you writing? What are these images? Why are they moving?
If you plan to move things with a loop you are going to have a problem. As I mentioned before, GUI programs are not supposed to wait. No long for loops. To allow any kind of interaction, your program will have to break the "moving image" into "moving image in baby steps" and periodically call a function to update the image position. In tkinter this is usually done using the after() function. Using after() you call a function every 50 milliseconds or so. The function moves your image, schedules itself to run again in 50 milliseconds (using after()), and returns. Now that mainloop() is not blocked from executing, changes made in the move function quickly appear in the window.
If you plan to move things with a loop you are going to have a problem. As I mentioned before, GUI programs are not supposed to wait. No long for loops. To allow any kind of interaction, your program will have to break the "moving image" into "moving image in baby steps" and periodically call a function to update the image position. In tkinter this is usually done using the after() function. Using after() you call a function every 50 milliseconds or so. The function moves your image, schedules itself to run again in 50 milliseconds (using after()), and returns. Now that mainloop() is not blocked from executing, changes made in the move function quickly appear in the window.