The Best 4 Python GUI libraries

Edward Low
4 min readOct 2, 2022

Way to use 4 Python Libraries to develop Desktop GUI Application

Photo by Sigmund on Unsplash

As the name implies, GUI (Graphical User Interface) is the use of visuals to show a more convenient and intuitive computer interface.

CUI (Command Line User Interaction) is a popular Dos command line operation that corresponds to it. It must learn a few frequently used instructions. It is quite tough for regular people to operate and learn.

A well-designed and simple-to-use user interface may substantially enhance everyone’s experience and increase efficiency.

If you want to create a calculator, for example, there is no user experience if all you have is a programmatic input and output window.

As a result, it is required to create a little graphical window.

1. PyQt5

Riverbank Computing is the creator of PyQt5. It is a cross-platform framework based on the Qt framework that can produce programs for a variety of platforms, including Unix, Windows, and Mac OS.

PyQt is a cross-platform application that mixes Qt with Python. It’s more than simply a graphical user interface toolkit. Threads, Unicode, regular expressions, SQL databases, SVG, OpenGL, XML, and a full-fledged web browser are all provided, as well as a large number of GUI widgets.

Installation:

pip install -i PyQt5

Code Snippets:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout



app = QApplication(sys.argv)
w = QWidget()
w.resize(500, 500)

w.layout = QVBoxLayout()
w.label = QLabel("Hello World!")
w.label.setStyleSheet("font-size:25px;margin-left:155px;")
w.setWindowTitle("PyQt5 Window")
w.layout.addWidget(w.label)
w.setLayout(w.layout)

w.show()
sys.exit(app.exec_())

Output:

Coded by Author (Copyright belongs to Author)

2. Tkinter

Tkinter is one of Python’s most widely used GUI libraries. It has been one of the primary options for novices in GUI programming due to its simple syntax.

Tkinter has a number of widgets, including labels, buttons, text fields, checkboxes, and scroll buttons, among others.

Because most of our programs are shown in rectangles, grid layouts make even complicated designs easy to implement.

Installation

pip install -i tkinter

Code Snippets:

Let’s use Tkinter to create a BMI calculator.

In a popup, it takes your weight and height as input and delivers your BMI coefficient.

from tkinter import *
from tkinter import messagebox

def get_height():
height = float(ENTRY2.get())
return height

def get_weight():
weight = float(ENTRY1.get())
return weight

def calculate_bmi():
try:
height = get_height()
weight = get_weight()
height = height / 100.0
bmi = weight / (height ** 2)
except ZeroDivisionError:
messagebox.showinfo("Info", "Height")
except ValueError:
messagebox.showinfo("Info", "Invalid Input!!")
else:
messagebox.showinfo("Your BMI is : ", bmi)

if __name__ == '__main__':

TOP = Tk()
TOP.bind("<Return>", calculate_bmi)

TOP.geometry("400x400")

TOP.configure(background="#03adfc")

TOP.title("BMI Calculator")
TOP.resizable(width=False, height=False)
LABLE = Label(TOP, bg="#03adfc", fg="#ffffff", text="BMI Calculator", font=("Helvetica", 15, "bold"), pady=10)
LABLE.place(x=55, y=0)
LABLE1 = Label(TOP, bg="#ffffff", text="Weight(Unit:kg):", bd=6,
font=("Helvetica", 10, "bold"), pady=5)
LABLE1.place(x=55, y=60)
ENTRY1 = Entry(TOP, bd=8, width=10)
ENTRY1.place(x=240, y=60)
LABLE2 = Label(TOP, bg="#ffffff", text="Height(Unit:cm):", bd=6,
font=("Helvetica", 10, "bold"), pady=5)
LABLE2.place(x=55, y=121)
ENTRY2 = Entry(TOP, bd=8, width=10)
ENTRY2.place(x=240, y=121)
BUTTON = Button(bg="#03a9fc", fg='#ffffff', bd=12, text="BMI", padx=33, pady=10, command=calculate_bmi,
font=("Helvetica", 20, "bold"))
BUTTON.grid(row=5, column=0, sticky=W)
BUTTON.place(x=115, y=250)
TOP.mainloop()

Output:

Coded by Author (Copyright belongs to Author)

3. Kivy

Kivy is another open-source Python library with the advantage of being able to create mobile applications rapidly (mobile phones).

Kivy is available for Windows, Mac OS, Linux, Android, iOS, and Raspberry Pi, among other platforms.

Under the MIT license, it is also free to use.

Installation

pip install -i kivy

Code Snippets:

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
def build(self):
return Button(text=" Hello World ")

TestApp().run()

Output:

Coded by Author (Copyright belongs to Author)

4. wxPython

wxPython is a cross-platform Python GUI framework that makes it simple to construct sophisticated and robust graphical user interfaces. It is, after all, written in C++.

Windows, Mac OS X, macOS, and Linux are currently supported.

On all systems, wxPython-based applications (GUIs) have a native appearance and feel.

Installation:

pip install -i wxPython

Code Snippets:

import wx

myapp = wx.App()
init_frame = wx.Frame(parent=None, title='WxPython Window')

init_frame.Show()
myapp.MainLoop()
Coded by Author (Copyright belongs to Author)

--

--

Edward Low

Data Engineer, Data Analyst, RPA Developer, Full-stack developer. Proficiency in Python, Django, ML, API Dev, React Js, C#, Nextjs, Flutter, and Algorithm