I know what is the purpose of mainloop (or at least i think), also i know that code placed after mainloop can be executed using after(), but why is like that? Why is mainloop blocking it?
1 Answer
When you use .mainloop() method, you start a special loop used by Tkinter to check for events like keypresses and button presses. It functions like a forever while loop. Therefore, you can't run any code outside of the loop until either the window is closed by the user or is destroyed in the code.
2 Comments
dj dj
Yeah, that comparison to while loop really helped me. Thanks!
TheEngineerGuy
No problem! It would be nice if you could accept the answer so others will know this question has been answered
.mainloop()does, then we could tell what you got wrong and what right, also the closes comparison to.mainloop()is asynchronous code, basically there is a loop that runs till stopped that handles all the events, obviously nothing can run after the loop until the loop has finished