Python GUI development

Mohammed Saiful Alam Siddiquee
5 min readFeb 6, 2020

Once you get settled into Python programming, you look forward to the more serious stuff, like application with GUI and so on. So what is your option with the GUI application building in Python? There are about 8 different GUI frameworks that you go choose from. These are:

1 Kivy
Kivy is an open-source Python library for the rapid development of applications that makes use of innovative user interfaces, such as multi-touch apps. This framework is a cross-platform and runs on Linux, Windows, OS X, Android, iOS, and Raspberry Pi. The graphics engine is built using a modem and fast graphics pipeline.

2 Libavg
Libavg is an open-source high-level development platform for media-centric applications. It uses Python as the scripting language, is written in high-speed C++ and uses modern OpenGL for display output. This framework is great for the development of modern touch UIs and supports all major touch driver models, including Windows touch, Linux XInput, and TUIO. Libavg has several features such as it supports the full variety of display elements which modern graphics-intensive applications needs, the layout engine supports thousands of display elements on the screen at once as well as a hardware-accelerated video output and much more.

3 PyQT
PyQt is a set of Python v2 and v3 bindings for The Qt Company’s Qt application framework and runs on all platforms supported by Qt including Windows, OS X, Linux, iOS and Android. This framework brings together the Qt C++ cross-platform application framework and the cross-platform interpreted language Python. Qt is a cross-platform application development framework for desktop, embedded and mobile. Qt includes abstractions of network sockets, threads, Unicode, regular expressions, SQL databases, SVG, OpenGL, XML, a fully functional web browser, a help system, a multimedia framework, as well as a rich collection of GUI widgets.

4 PySimpleGUI
PySimpleGUI is a GUI framework for Python which supports Python 3 version. It is simple to create custom GUIs with the help of this framework. Currently, there are 4 actively developed and maintained “ports” of this framework which are Tkinter which is fully complete, Qt using Pyside2 which is at alpha stage, WxPython which is at the development stage and Remi (Web browser support) which is also at the development stage.

5 Pyforms
Pyforms is a cross-environment framework for developing GUI applications. The framework offers a Python layer of desktop forms, based on PyQt, OpenGL and other libraries, allow applications to run on Desktop GUI, Web and terminal without requiring code modifications. Pyforms promotes modular software design and code reusability with minimal effort.

6 Tkinter
Tkinter or Tk interface is Python’s de-facto standard GUI (Graphical User Interface) package. This is an open-source framework and is available on platforms like Unix and Windows. It is one of the simplest and most popular ways to build a GUI-based application in Python.

7 Wax
Wax is a Python GUI framework that sits atop wxPython (wxWindows for Python). This framework removes the low-level aspects of wxPython (which is basically a direct binding to the ugly C API) and gives you simple python objects to create your GUI. It also runs on many platforms (Win32, Linux w/ GTK, and macOS/OSX w/ Carbon).

8 WxPython
WxPython is an open-source cross-platform GUI toolkit for Python. It is implemented as a set of Python extension modules that wrap GUI components of the popular wxWidgets cross-platform library, which is written in C++. With the help of this framework, developers can create native user interfaces for their Python applications that run on Windows, Macs, and Linux or other Unix-like systems. Since the programming language is Python, wxPython programs are simple, easy to write and easy to understand.

My Experience:

I have used a few from the list above. Kivy is very good for a game-like environment. And it is very fast compared to other GUI frameworks in Python. Most of the Python GUI users start with Tkinter. The good thing about TKinter is that it comes with most of the Python installations, so you don’t need to look for it. For all of these Frameworks, it needs a good amount of research to figure out the functional designs of your Python application with GUI so that the GUI front-end is not frozen during a long calculation.

I found the ‘PySimpleGUI’ is the best in terms of the minimality of coding to create any GUI element, whether it is a dialog box or a progress meter. A progress meter can be written in one-liner Python code.

An Example GUI:

The following GUI with 13 different graphic elements is created only with 35 lines of Pythonic code! Isn’t it amazing? Let’ see the code below [source: https://pysimplegui.readthedocs.io/en/latest/cookbook/]

#!/usr/bin/env Python3 
import PySimpleGUI as sg
sg.ChangeLookAndFeel(‘GreenTan’)# — — — Menu Definition — — — #
menu_def = [[‘File’, [‘Open’, ‘Save’, ‘Exit’, ‘Properties’]],
[‘Edit’, [‘Paste’, [‘Special’, ‘Normal’, ], ‘Undo’], ],
[‘Help’, ‘About…’], ]
# — — — Column Definition — — — #
column1 = [[sg.Text(‘Column 1’, background_color=’#F7F3EC’, justification=’center’, size=(10, 1))],
[sg.Spin(values=(‘Spin Box 1’, ‘2’, ‘3’), initial_value=’Spin Box 1')],
[sg.Spin(values=(‘Spin Box 1’, ‘2’, ‘3’), initial_value=’Spin Box 2')],
[sg.Spin(values=(‘Spin Box 1’, ‘2’, ‘3’), initial_value=’Spin Box 3')]]
layout = [
[sg.Menu(menu_def, tearoff=True)],
[sg.Text(‘All graphic widgets in one window!’, size=(30, 1), justification=’center’, font=(“Helvetica”, 25), relief=sg.RELIEF_RIDGE)],
[sg.Text(‘Here is some text…. and a place to enter text’)],
[sg.InputText(‘This is my text’)],
[sg.Frame(layout=[
[sg.Checkbox(‘Checkbox’, size=(10,1)), sg.Checkbox(‘My second checkbox!’, default=True)],
[sg.Radio(‘My first Radio! ‘, “RADIO1”, default=True, size=(10,1)), sg.Radio(‘My second Radio!’, “RADIO1”)]], title=’Options’,title_color=’red’, relief=sg.RELIEF_SUNKEN, tooltip=’Use these to set flags’)],
[sg.Multiline(default_text=’This is the default Text should you decide not to type anything’, size=(35, 3)),
sg.Multiline(default_text=’A second multi-line’, size=(35, 3))],
[sg.InputCombo((‘Combobox 1’, ‘Combobox 2’), size=(20, 1)),
sg.Slider(range=(1, 100), orientation=’h’, size=(34, 20), default_value=85)],
[sg.InputOptionMenu((‘Menu Option 1’, ‘Menu Option 2’, ‘Menu Option 3’))],
[sg.Listbox(values=(‘Listbox 1’, ‘Listbox 2’, ‘Listbox 3’), size=(30, 3)),
sg.Frame(‘Labelled Group’,[[
sg.Slider(range=(1, 100), orientation=’v’, size=(5, 20), default_value=25),
sg.Slider(range=(1, 100), orientation=’v’, size=(5, 20), default_value=75),
sg.Slider(range=(1, 100), orientation=’v’, size=(5, 20), default_value=10),
sg.Column(column1, background_color=’#F7F3EC’)]])],
[sg.Text(‘_’ * 80)],
[sg.Text(‘Choose A Folder’, size=(35, 1))],
[sg.Text(‘Your Folder’, size=(15, 1), auto_size_text=False, justification=’right’),
sg.InputText(‘Default Folder’), sg.FolderBrowse()],
[sg.Submit(tooltip=’Click to submit this window’), sg.Cancel()]
]
window = sg.Window(‘Everything bagel’, layout, default_element_size=(40, 1), grab_anywhere=False)event, values = window.read()sg.popup(‘Title’,
‘The results of the window.’,
‘The button clicked was “{}”’.format(event),
‘The values are’, values)
All visual elements of a GUI only in 35 lines of Python code

--

--

Mohammed Saiful Alam Siddiquee

I am a Professor of Civil Engineering. Always, I wanted to be a writer. Medium has opened up this opportunity. I need support from the readers of Medium.