What does calling Tk() actually do?

PythonTkinterServer Side ProgrammingProgramming

Tkinter is a Python package which comes with many functions and methods that can be used to create an application. In order to create a tkinter application, we generally create an instance of tkinter frame, i.e., Tk(). It helps to display the root window and manages all the other components of the tkinter application. We can initialize the tkinter instance by assigning the variable to it.

Example

In the following example, we will create an instance of tkinter frame and create a label widget.

#Import tkinter library
from tkinter import *
#Create an instance of tkinter frame or window
win= Tk()
#Set the geometry of tkinter frame
win.geometry("750x250")
#Create a Label widget
label= Label(win, text="Open Source Learning is Awesome!", font= ('Courier 20 underline'))
label.pack()
win.mainloop()

Output

raja
Published on 22-Apr-2021 07:52:38
Advertisements