Why isn't mainloop() at the start of your code instead of the end?

61 Views Asked by At

I understand how the function works itself, however, mainloop() is usually at the end of your code in modules like turtle and tkinter and you're required to put it at the end or there will be a syntax error and/or the remaining code is discarded

Since Python is a step by step process, wouldn't it make more sense for it to be put at the start?

1

There are 1 best solutions below

0
LhasaDad On

Python executes your file from top to bottom. This includes setting global variables and defining classes and functions. Putting the main_loop at the bottom allows for all that setup and definition to occur before you actually need it in the main_loop call.