You learn the basic idea of the Python GUI programming via the tkinter module in this post. This tutorial is mainly designed to understand the simple tkinter concept that allows you to build any Python GUI.
GUI: GUI is a basic program that allows users to communicate with their machine through a graphical interface.
tkinter is a built-in Python framework for GUI development.
Python offers a variety of GUI choices like tkinter, pyqt and others.
The most popular way to create a graphical application is tkinter.
Apps are constructed like this:
- Import the tkinter module
- Build the window of the GUI application
- In the main window of a Interface program, add some amount of widgets
- Start the main loop
import tkinter as tk from tkinter import * Example = tk.Tk() rad1=Radiobutton(Example, text='Content', value=1) rad1.pack() rad2=Radiobutton(Example, text='Software', value=2) rad2.pack() label=Button(Example,text='Welcome to Example', width=100) label.pack() Example.mainloop()
.mainloop() when ready to run a program. This shows the window until it's closed.
Widgets can be placed in 3 ways:
the widgets put in the widget parent.
the grid widgets are put in the parent widget.
positions them at different points that we control.
# button button_name=tkinter,Button( parent, text='your text', width='width_of_text', command='function to call') # radio button rad1=Radiobutton( parent, text='your text', value=numerical_value).pack() # listbox List=Listbox(parent) List.insert(1, text) List.insert(2, nexttext) # Entry label1=Label(parent, text='Name').grid(row=0) label2=Label(parent, text='password').grid(row=1) entry_in_label1 = Entry(parent) entry_in_label2 = Entry(parent) entry_in_label1.grid(row=0, column=1) entry_in_label2.grid(row=1, column=1)
If you are new to tkinter, I recommend this course