To begin, we will first import the Tkinter module. It contains all the classes and functions required by the TK Toolkit and what it needs, and in general, you can import all of the Tkinter's properties and methods directly into your module's namespace:
From Tkinter Import *
Initialization Tkinter You must first create a TK root component. You only need to do this one time in each program, and you must first be created before other components are created.
root = Tk ()
Next, we create a label component as a child part of the root window:
W = Label (Root, text= "Hello, world!") W.pack ()
A Label component can display any text, icon, or picture. Here, we use the text option to specify the text to display. We then call the pack method of the component to tell it to set the appropriate area to display the text and display it. After all this work, We also specify the Tkinter event loop::
Root.mainloop ()
The program will stay on the event loop until we close the window. Event loops are used not only to handle user events (such as mouse clicks and keystrokes) or window system events (such as redrawing Windows and window configuration information), but also to handle tkinter operations queues, which are both geometry management (Pack method queues) and display updates. . This also means that the application window will not be displayed before the main loop (main loop).