You are currently viewing How To Create GUI Application In Python Using Tkinter 2021?
create gui application in python using tkinter

How To Create GUI Application In Python Using Tkinter 2021?

Create GUI  application in python using Tkinter . Python is one of the  popular computer programming language which support lot of framework to build GUI  application. Python is use for various sector and different purpose.

Python Use For || Create GUI Application In Python Using Tkinter:

  1. Ethical Hacking (write your own exploit).
  2. Web application using DJango framework.
  3. Desktop Application Develop which support multi operating system.
  4. Artificial intelligent
  5. Automation
  6. Data Analysis.
  7. Data Science.
  8. Games Development.
  9. AI And Machine Learning.
  10. Data Visualization.

In this article we learn how to create GUI application in python using tkinter framework. In python there are lot of GUI framework which use to create GUI application. Some of these are following.

Python GUI Application Framework :

  1. Tkinter
  2. Flex
  3. CEF Python
  4. Kivy (Developing Mobile Application (Android And IOS)
  5. Dabo
  6. Payforms
  7. PyGObject
  8. PyQT
  9. PySide
  10. PyGUI

How to install Tkinter  Module In Pycharm?

To integrate Tkinter framework with python you need to include following method in namespace top of your python file which you have created for GUI.

Also read my previous article how to create SQLite3 connection with python.

Tkinter module are consist of widgets  or GUI elements these widgets are lable, textfield, dropdown lists, grid, lists, command button, masks, input field and much more. Elements are contain inside the GUI like windows.

Here are few simple step to installing Tkinter Module in Pycharm follow these

If you want to install tikinter module in Linux you need to first update your Linux system.

Open your Linux terminal and enter following command.

Create GUI  application in python using Tkinter:

Tkinter Intalling In Linux:

Sudo apt-get update

Sudo apt-get installs python 3.8 python-3 tk

Tkinter Intalling In Windows:

from tkinter import *

Note: If you face problem like below while installing it then you will need to install tk package.

Create Gui Application In Python Using Tkinter
Create Gui Application In Python Using Tkinter

Create a window write the following code in your python file.

#Create GUI  application in python using Tkinter
root = Tk()
root.mainloop()

Create Gui Application In Python Using Tkinter

Before placing the elements on window in tkinter first we need to see all basic widgets which use to creating GUI application in python using Tkinter. So some of basic elements are following.

Python Tkinter widgets or Elements:

  1. Title of window (which written on the title bar)
  2. Label (use for define the element)
  3. Text entry (use for get user input data)
  4. Command button (define the action of user)
  5. Dropdown list
  6. List element
  7. Check box
  8. Radio button
  9. Menu bar
  10. Date time picker
  11. Mask field
  12. Open file dialog
  13. New window
  14. Table
  15. Group box

Now we see the above elements with example and use these in Tkinter sample projects.

1.     Window Title

A Window title is the basic and first element in tkinter when you creating GUI application in python firsts you write your window title. So user easily understand the window function. Below is the example and  how to write your window title in tkinter.

root = Tk()
root.geometry("500x300")
root.title("User Signup")

2.     Label

A label element is use for understand the other element. It is use for guide for user to understand the element of function. It helps the user to when enter the record in application. He easily input the data in text filed by reading these elements.

                Label Factor

a). text is use place on the label which help the use what he will put and which element related to.

b). If your text is log then you will need to increase the label width.

c). formatting label: to create your attracting GUI application in python using tkinter you must format label i.e font size, font style, font color and background color of lable.

d). location of label is very import label is place on the window and must require the location. You need to top indent use of x and y use of left indent space.

Below is the simple example of label

label1 = Label(root, text=”Enter Username”, relief=”solid”, width=20, font=(“arial”, 19, “bold”))

label1.place(x=90, y=53)

Set the font color and back color of label

Change the background color of label or any other element adds the following code in above label.

bg="yellow"

Change the font color:

fg="blue"
label1 = Label(root, text="Enter Username :", width=15, bg="yellow", fg="blue", font=("arial", 12,))
label1.place(x=60, y=70)

Note: you can place the color code instead of define color name.

 

3.     Text Entry:

In GUI application development you will need to place more widgets or text entry in your application. So I recommended you make a master template. Once a template you designed you don’t need to create again. And it will help you NRY (No Repeat Yourself)

A text entry use in Tkinter to get the required information from the users. Here user inpurt the required information which given to him, and that information save to the database server. It help the business to analysis the data.

Example:

entry_1 = Entry(root)
entry_1.place(x=220, y=70)

label1 = Label(root, text="Enter Username :", width=15, bg="yellow", fg="blue", font=("arial", 12,))
label1.place(x=60, y=70)
entry_1 = Entry(root)
entry_1.place(x=220, y=70)

4.     Command Button:

Command button is use to perform the action by user. A function is defining in python and calls it on the command button. A command button has many events but here we see the basic on click event.

For example we create a simple  button when uer click on this button then a function will call. In function we write the about application developer. And call it Onclick or command event.

Create Function:

Before defining the function you will need to import the messagebox from tkinter module. For this write the code in your python on namespace.

import tkinter.messagebox
# define function
def about():
tkinter.messagebox.showinfo(" Welcome ", 'this software developed by sadaqat hussain')

Create a button:

Create button with the name of button_abt and write text , setup location like below.

but_abt = Button(root, text="About", width=12, bg='brown', fg='white', command=about).place(x=220, y=230)

Run the application and click on this button you will see the follow message.

5.     Dropdown List

Drop download is consisting of option text. The list may be the country, gender, category and much more. In this user can choose only one option from the dropdown.

Here we create a simple country list and call it in dropdown.

country = StringVar()

label4 = Label(root, text="Select Country :", width=20, font=("arial", 10, "bold"))
label4.place(x=80, y=130)

list_1 = ['Pakistan', 'India', 'UAE', 'Iran', 'China']
droplist = OptionMenu(root, country, *list_1)
country.set("Select Country")
droplist.config(width=15)
droplist.place(x=220, y=130)

6.     Checkbox:

This element use in python GUI application development using Tkinter for multiple choice. For example a user have multiple hobbies then we place a 4 check boxes and assign the four hobbies.

label3 = Label(root, text="Hobies :", width=20, font=("arial", 10, "bold"))
label3.place(x=80, y=160)

c1 = Checkbutton(root, text="Cricket").place(x=210, y=160)
c2 = Checkbutton(root, text="Football").place(x=270, y=160)
c3 = Checkbutton(root, text="Hocky").place(x=330, y=160)
c4 = Checkbutton(root, text="Other").place(x=390, y=160)
creating gui application in python using tkinter

 7.     Radio Button:

Radio Button is use to choose to once option from the radio group.

Example:

Here we create two radio option with assign a gender text. One is Male and  second is female.

label3 = Label(root, text="gendre :", width=20, font=("arial", 10, "bold"))
label3.place(x=80, y=200)
r1 = Radiobutton(root, text='Male', value='Male').place(x=190, y=200)
r2 = Radiobutton(root, text='Female', value='Female').place(x=250, y=200)

Tkinter GUI Examples

creating gui application in python using tkinter

8. Date Time Calander || Create GUI Application In Python Using Tkinter

While creating GUI application in python using tkinter you need to install calendaar package which very important for user and back end in the database.

In tkinter calander is use to select the custom date, month and year in GUI application. To place a date calendar you to to install some packages in your project files. How to install calendar  in python follow these few simple steps:

Step 01 : Import tkcalendar package in python file on top namespace.

from tkcalendar import Calendar, DateEntry

Here I import two module first calendar and 2nd is DataEntery. The Calendar is only show the current date,month and year in calendar you can’t select custom date in input field. But in DataEntry you select date, month and year and place in text entry field.

Example:

cal = DateEntry(root,width=30,bg="darkblue",fg="white",year=2021).place(x=190, y=220)

Output Is:

 

Tkinter GUI Examples

tkinter calander picket

9. Menu In Tkinter

Menu bar is the most important element while you create GUI application in python using tkinter. The menu should be attractive because it place top of you dashboard. User put first look on it. Design it according to your application function. How to create menu in tkinter it is so simple just follow these steps.

subm1 = Menu(menu)
menu.add_cascade(label="File", menu=subm1)
subm1.add_command(label="Exit", command=abt)

subm2 = Menu(menu)
menu.add_cascade(label="option", menu=subm2)
subm2.add_command(label="Edit", command=abt)
how to create menu in tkinter

This Post Has 7 Comments

  1. Bernd

    It’s going to be finish of mine day, however
    before ending I am reading this fantastic post
    to increase my knowledge.

  2. Push it to the limit cool Wolf you are the best and you can do everything https://www.samsung.com smkmkplobydlmcrjmzgvx 0837959

    Push it to the limit cool Wolf you are the best and you can do everything https://www.samsung.com smkmkplobydlmcrjmzgvx

  3. Push it to the limit cool Wolf you are the best and you can do everything https://www.samsung.com smkmkplobydlmcrjmzgvx 6484349

    Push it to the limit cool Wolf you are the best and you can do everything https://www.samsung.com smkmkplobydlmcrjmzgvx

  4. От 25 000 рублей с САЙТА и РЕКЛАМНОЙ КАМПАНИИ. Подробнее по ссылке: https://google.com 6419339

    От 25 000 рублей с САЙТА и РЕКЛАМНОЙ КАМПАНИИ. Подробнее по ссылке: https://google.com

  5. От 25 000 рублей с САЙТА и РЕКЛАМНОЙ КАМПАНИИ. Подробнее по ссылке: https://google.com 6474193

    От 25 000 рублей с САЙТА и РЕКЛАМНОЙ КАМПАНИИ. Подробнее по ссылке: https://google.com

Leave a Reply