Tkinter is a GUI library in Python that is a fast and easy way to create GUI applications.
To open Tkinter, follow the following steps:
Tkinter
modulename.mainloop()
The following steps are shown in the code below:
from tkinter import *obj = Tk()obj.mainloop()
The Button
object is used to display the button on your application:
new_button = Button(text= "button", command ="")new_button.pack()
The Entry
object is used to display a single input text field line:
text_field = Entry()text_field.pack()
The Label
object is used to display a single text field line:
main_title = Label(text = "Hello")main_title.pack()
All the widget has to use is a specific geometry method and it is divided into three types. These types are:
Pack
: organizes the widgets before placing them in the parent widget.new_button = Button(text= "button", command ="")new_button.pack(side = BOTTOM)text_field = Entry()text_field.pack(side = LEFT)main_title = Label(text = "Hello")main_title.pack(side= RIGHT)
Place
: you can provide an absolute position for where to place the widget.new_button = Button(text= "button", command ="")new_button.place(height = 100, width = 100)
Grid
: displays widgets in Table format.new_button = Button(text= "button",width = 40, command ="")new_button.grid(row = 1, column = 0,columnspan = 2)text_field = Entry()text_field.grid(row = 0, column =1)main_title = Label(text = "Hello")main_title.grid(row = 0, column = 0)