Topic: Create and Show tkinter Root Window
What is a Root Window in tkinter
A Python 3 Graphical User Interface Program always contains a root window . The root window is the main window of the Python GUI program. This main window will have the other GUI elements which are called widgets. For example, we can use widgets like button, lable, entry, radio button and check button etc.
Creating a Root Window in tkinter
The tkinter GUI module provides a class Tk. We use the contructor of Tk class to craete an instance which is the root window of the program.
The Python 3 Code To Create a Root Window
window = tk.Tk()
The Complete Code for tkinter Root Window
Explanation of Code in the Image
- Imports tkinter module, use tk as an alias. Because tk is short and easy to use in code.
- Header of main() function.
- Indented body of main() function . Create main window or Root window of the application.
- When this line of code will execute, it will start the mainloop that is event loop. So that the output root window is shown to the user. It will wait for any actions called events performed by the user and the code attached, if any, will respond to those events. For example, if we click on close button, the window will be closed.
- Call to main() function. Now the execution of the program will start and the root window will be displayed on the screen.