DEV Community


Posted on

tkinter gui

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.

GUI tkinter module

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)
rad2=Radiobutton(Example, text='Software', value=2)
label=Button(Example,text='Welcome to Example', width=100)


tk example

.mainloop() when ready to run a program. This shows the window until it's closed.

Widgets can be placed in 3 ways:

  1. pack():
    the widgets put in the widget parent.

  2. grid():
    the grid widgets are put in the parent widget.

  3. place():
    positions them at different points that we control.

Tkinter lets you place all kinds of widgets like buttons, radiobuttons, listbox etc.

# button
       text='your text', 
       command='function to call')

# radio button    
       text='your text', 

# listbox
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)

You can make a GUI for any type of code, like a bmi calculator, notifications, progressbar, canvas etc.

If you are new to tkinter, I recommend this course

Top comments (1)

shivamkumraa9 profile image

Thank you for these code examples. BTW I have also created a login form GUI by using Tkinter. Here is the picture of that. For more such valuable code examples. Please kindly refer to my blog