We will start our Tkinter journey with popular
Hello World program.
The window will be like this:
Tkinterin Python 2 to
tkinterin Python 3. Therefore if you want to write Python 2 and 3 compatible Tkinter codes, you need to check the Python major version number before importing Tkinter.
For Python 2
import Tkinter as tk
For Python 3
import tkinter as tk
In the next line
app = tk.Tk()
The app window that is a main window could have other widgets like labels, buttons, and canvas in itself. It is the parent window of all its widgets.
It names the main window as “Hello World”.
After window instance is created,
mainloop() should be called to let window enter the endless loop, otherwise nothing will show up.