What is the mainloop functionality in the Tkinter frame?

Asked

Viewed 26 times

-3

I was trying to make a frame appear on the screen on Tkinter, and after a lot, I tried to check the documentation and saw the name "mainloop", when testing it appeared on the screen, which I did not understand, since when I called through the pack it did not work, only when I put this mainloop.

(PS: I checked if it was a different frame instance, but it was the frame instance)

Please would someone please explain to me what this frame mainloop does, because in Tkinter’s own Docs it is very incomplete.

1 answer

0


The method mainloop is used to "lock" running the current window using an Event loop of tkinter. This allows the tkinter can trigger responses to events in the current instance of the window that called the mainloop, as a keypress or click and does not allow the execution of later codes until the window is closed. You can test this by calling the method mainloop with a code soon after and you will see that it will only be executed after:

window = Tk()
window.mainloop() 
# esse print não será chamado até que feche a janela que chamou o método mainloop
print('chamou')

The print called is only executed when the current window leaves the process of mainloop, that is, have your instance finished.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.