When do I need to call the main loop in a Tkinter application?


Python Tkinter is a standard library that is used to develop GUI-based featured and functional applications. Whenever we execute our application, it displays a general window that contains some widgets and a title bar in it. The mainloop() method is responsible for executing the script and displaying the output window. However, mainloop() implies that it doesn't terminate automatically until the user remains in the window. Whenever the user terminates the program, it gets closed automatically. The mainloop() method gets called whenever the program starts executing.


# Import the required libraries
from tkinter import *

# Create an instance of tkinter frame
win = Tk()

# Add a Label widget
Label(win, text="This is a New Line Text", font= ('Times New Roman', 18,'bold')).pack(pady= 40)


Executing the above code will display a new window with some text message in it.

Published on 07-Jun-2021 11:23:29