Tkinter – First Tkinter Program
Open your favorite code editor and copy-paste the following code and Try to run
from tkinter import * root = Tk() root.mainloop()
When you run the above code, The code generates a window screen and displays it on the screen like this.
Let’s try to understand the code.
from tkinter import *
Here we are trying to import all the functions and methods available inside the Tkinter module into our current project/program. You can specify the function if you are sure which function basically you want.
root = Tk()
Tk is the name of the top-level windows widget class that represents a window. It has a built-in Tcl interPreter. So using the above statement, we just created an object root.
mainloop( ) is a function associated with the class Tk() thus we are able to call this function from our object. The mainloop function will keep your screen open until you manually close the window.