Previous | Tutorial index | Next
Tutorial 2: Overview of Python Libraries for GUI Development
Learning Objectives
- Explain which Python libraries are available for developing GUI‑based applications.
- Compare and contrast the major GUI libraries based on licensing, complexity, use cases, and platform support.
- Make an informed decision about which library to use for a given project.
1. Introduction – The GUI Library Landscape
Python is one of the most versatile programming languages, and its ecosystem offers dozens of GUI libraries. Each library has its own philosophy, target audience, and set of trade‑offs. Some are built into Python itself, while others require separate installation. Some aim for maximum platform fidelity (native look‑and‑feel), while others prioritise cross‑platform consistency or modern touch interfaces.
In this tutorial, we will explore the most popular and mature options. By the end, you will understand why we choose Tkinter for this course, but you will also know what alternatives exist for more advanced projects in your future career.
2. Library 1: Tkinter – The Standard Built‑In Solution
2.1 What Is Tkinter?
Tkinter is the de facto standard GUI library for Python. It is bundled with virtually every Python distribution (including the official installer from python.org). You do not need to install anything extra – it is ready to use as soon as Python is installed.
Under the hood, Tkinter is a thin wrapper around Tk, a mature, open‑source GUI toolkit that was originally developed for the Tcl scripting language. Tk has been around since the early 1990s and has been ported to all major operating systems.
2.2 Key Features
- Lightweight – The core library is small and has minimal dependencies.
- Stable and proven – Tk has been used in production for decades.
- Cross‑platform – Applications look reasonably consistent across Windows, macOS, and Linux.
- Simple widget set – It provides all the essential widgets: buttons, labels, text entries, menus, canvases, etc.
- No external dependencies – You don't need to install any third‑party packages to get started.
2.3 Limitations
- Outdated appearance – Classic Tk widgets look like they belong to the 1990s (grey, chunky 3D borders). However, the
ttk (themed) submodule (introduced in Tutorial 10) gives a more modern look.
- Limited advanced widgets – There is no built‑in support for advanced charts, 3D graphics, or rich text editors (though you can extend it).
- Not ideal for mobile – Tkinter was never designed for touch screens or mobile platforms.
2.4 Quick Start Code
import tkinter as tk
root = tk.Tk()
root.title("My Tkinter App")
label = tk.Label(root, text="Hello from Tkinter!")
label.pack()
root.mainloop()
2.5 When to Choose Tkinter
- You are a beginner learning GUI concepts.
- You need to build a small to medium‑sized desktop application quickly.
- You cannot install external libraries due to corporate restrictions.
- You are writing a utility for internal use (e.g., a dashboard for your team).
3. Library 2: PyQt & PySide – The Enterprise Powerhouses
3.1 What Are They?
PyQt and PySide are two separate Python bindings for the Qt framework (pronounced "cute"). Qt is a colossal C++ framework developed by The Qt Company. It is one of the most complete and sophisticated GUI toolkits in existence.
- PyQt is developed by Riverbank Computing. It is the older of the two and has been around since 1998.
- PySide (also known as "Qt for Python") is the official binding from The Qt Company itself, released in 2009 to support the Qt ecosystem more directly.
3.2 Key Features (Both)
- Vast widget library – Thousands of widgets, including advanced ones like tree views, table views, charting, web engines, multimedia players, and 3D rendering (OpenGL).
- Qt Designer – A drag‑and‑drop visual UI designer that generates
.ui files, which you can convert to Python code. This speeds up UI development enormously.
- Signals & Slots – A powerful mechanism for communication between objects (more flexible than simple callbacks).
- Native look – Qt renders widgets using the platform's native API (Windows, macOS, Linux), so your app blends in seamlessly.
- Cross‑platform – One codebase runs on Windows, macOS, Linux, Android, and iOS (though mobile support requires extra work).
- Internationalisation – Built‑in support for multiple languages and right‑to‑left scripts.
3.3 The Critical Difference: Licensing
| Aspect |
PyQt |
PySide |
| License |
GPL (v3) or commercial. |
LGPL (v3) or commercial. |
| Cost for closed‑source |
You must buy a commercial license if you do not want to open‑source your code. |
You can keep your code closed‑source as long as you dynamically link to the library (which Python does by default). |
| Popularity |
More widely used historically (many existing tutorials). |
Gaining ground as the "official" Qt binding. |
| API |
Very similar – almost identical. Code can often be ported with minor changes. |
Nearly identical to PyQt. |
Recommendation: For hobby projects and open‑source work, either is fine. For commercial (closed‑source) products, PySide is usually preferred to avoid licensing costs.
3.4 Quick Start Code (PySide6)
from PySide6.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout
app = QApplication([])
window = QWidget()
window.setWindowTitle("My PySide App")
layout = QVBoxLayout()
label = QLabel("Hello from PySide!")
layout.addWidget(label)
window.setLayout(layout)
window.show()
app.exec()
3.5 When to Choose PyQt/PySide
- You are building a large, complex desktop application (e.g., a CAD tool, an IDE, a media editor).
- You need advanced widgets (charts, 3D, web views).
- You want to use a visual designer to speed up UI layout.
- You are developing for multiple platforms and need a consistent, professional look.
- You are comfortable with a steeper learning curve.
4. Library 3: wxPython – Native Fidelity
4.1 What Is wxPython?
wxPython is a Python wrapper for wxWidgets, a C++ framework that prides itself on using native platform widgets wherever possible. On Windows, it uses Win32 APIs; on macOS, it uses Cocoa; on Linux, it uses GTK+. This means your application looks and behaves exactly like a native application on each platform – not "close to native," but actually native.
4.2 Key Features
- True native look – Buttons, scrollbars, and menus are drawn by the operating system itself.
- Large widget set – Comparable to Qt, with support for tree controls, HTML rendering, and printing.
- Cross‑platform – One codebase that compiles and runs on all major desktops.
- Mature and stable – wxWidgets has been active since 1992, and wxPython since 1998.
- No special licensing restrictions – It uses a permissive license (wxWindows Library Licence, which is essentially LGPL with an exception).
4.3 Limitations
- Lacks a visual designer – Unlike Qt, there is no official drag‑and‑drop UI builder (though third‑party tools exist).
- Smaller community – Fewer tutorials and examples compared to Tkinter and PyQt.
- Installation can be tricky – On some Linux distributions, you need to install system‑level wxWidgets libraries.
- Not suitable for mobile – wxWidgets does not support Android or iOS well.
4.4 Quick Start Code
import wx
app = wx.App()
frame = wx.Frame(None, title="My wxPython App", size=(300, 200))
panel = wx.Panel(frame)
label = wx.StaticText(panel, label="Hello from wxPython!", pos=(50, 50))
frame.Show()
app.MainLoop()
4.5 When to Choose wxPython
- You need your application to have a flawless, native appearance on each OS – it is critical for professional or enterprise software.
- You cannot use Qt due to licensing concerns, but you still need a rich widget set.
- You are targeting only desktop platforms (Windows, macOS, Linux) and do not care about mobile.
5. Library 4: Kivy – The Modern, Multi‑Touch Contender
5.1 What Is Kivy?
Kivy is an open‑source Python library specifically designed for multi‑touch applications and modern user interfaces. Unlike the previous libraries, Kivy does not use native widgets; instead, it draws everything using OpenGL ES 2. This gives it complete control over the visual appearance and makes it highly portable to mobile platforms.
5.2 Key Features
- Multi‑touch out of the box – Supports gestures (pinch, swipe, rotate) natively.
- Cross‑platform – Runs on Windows, macOS, Linux, Android, and iOS. In fact, Kivy is one of the few Python libraries that can easily package an app for the Apple App Store or Google Play Store.
- Modern, customisable UI – You can create smooth, animated, and visually stunning interfaces without being constrained by native widget limitations.
- KV Language – Kivy has its own declarative language (similar to CSS/QML) that separates UI design from application logic, making development cleaner.
- Built‑in widgets – Provides a rich set of touch‑friendly widgets: buttons, sliders, switches, lists, etc.
5.3 Limitations
- Non‑native look – Because it renders everything itself, the UI does not look like a native Windows or macOS app. This can be a deal‑breaker for desktop enterprise users.
- Smaller ecosystem – Fewer third‑party widgets compared to Qt.
- Installation overhead – Requires several dependencies (SDL2, GStreamer, etc.). On Android/iOS, it requires a separate packaging tool (Buildozer).
- Performance – For heavy 3D graphics or large data visualisations, it may be slower than Qt's OpenGL integration.
5.4 Quick Start Code
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text="Hello from Kivy!")
if __name__ == "__main__":
MyApp().run()
5.5 When to Choose Kivy
- You are building a mobile‑first application (Android/iOS) and want to use Python.
- Your application requires touch gestures (e.g., a drawing app, a game, an interactive kiosk).
- You want a highly custom, animated UI that does not look like a standard desktop app.
- You do not mind a non‑native appearance and users are tech‑savvy.
6. Other Notable Libraries (Briefly)
| Library |
Description |
Best For |
| PyGTK / PyGObject |
Python bindings for GTK+, the toolkit behind GNOME desktop. |
Linux‑first applications; integrates perfectly with GNOME. |
| Dear PyGui |
A Python wrapper for the Dear ImGui (immediate‑mode) C++ library. Extremely fast and uses modern GPU rendering. |
High‑performance applications like game dev tools, machine learning dashboards, and scientific visualisation. |
| Flexx |
A pure‑Python library that uses Web technology (HTML5, CSS, JavaScript) to create desktop and web apps. |
Applications that need to run both as a desktop app and as a web app from the same codebase. |
| PySimpleGUI |
A wrapper that sits on top of Tkinter, Qt, wxPython, and Remi. It offers a dramatically simplified API. |
Beginners who want to build GUIs in just a few lines of code, or for quick throwaway scripts. |
7. Comprehensive Comparison Table
| Feature |
Tkinter |
PyQt/PySide |
wxPython |
Kivy |
| Built‑in? |
✅ Yes |
❌ No |
❌ No |
❌ No |
| License |
PSF (free) |
GPL/LGPL |
wxWindows (free) |
MIT (free) |
| Widget Set Size |
Small (basic) |
Massive (advanced) |
Large |
Moderate |
| Native Look |
❌ No (classic) / Ttk improves |
✅ Yes |
✅ Yes (excellent) |
❌ No (custom drawn) |
| Mobile Support |
❌ No |
❌ Limited (Android/iOS) |
❌ No |
✅ Yes (Android/iOS) |
| Visual Designer |
❌ No (basic tools exist) |
✅ Qt Designer |
❌ No (third‑party only) |
❌ No (KV language) |
| Learning Curve |
✅ Very Low |
❌ High |
Medium |
Medium |
| Community Size |
✅ Very Large |
✅ Very Large |
Medium |
Growing |
| Performance |
Good |
Excellent |
Good |
Good |
| Typical Use Case |
Small utilities, internal tools |
Professional desktop apps |
Native enterprise apps |
Mobile apps, touch interfaces |
8. How to Choose the Right Library – A Decision Flowchart
-
Is the user non‑technical and on a desktop?
- Yes → Go to question 2.
- No (developer/internal) → Tkinter or PySimpleGUI is sufficient.
-
Do you need a flawless native appearance on Windows/macOS?
- Yes → Choose wxPython (or PyQt if you want a designer).
- No → Go to question 3.
-
Do you need mobile (Android/iOS) support?
- Yes → Choose Kivy.
- No → Go to question 4.
-
Is your application large, complex, or requiring advanced widgets (charts, 3D)?
- Yes → Choose PyQt/PySide.
- No → Choose Tkinter for simplicity and zero installation hassle.
9. Why This Course Uses Tkinter
Despite the existence of more powerful libraries, this course focuses on Tkinter for the following reasons:
- Zero setup – Students can start coding immediately without struggling with installation errors.
- Universal availability – Works on every lab computer, regardless of operating system.
- Teaches core GUI concepts – Layout management, event handling, widget configuration – these concepts transfer directly to any other GUI library.
- Gentle learning curve – Students can concentrate on programming logic rather than fighting with a complex API.
- Sufficient for course projects – The projects in this course (calculator, text editor, simple games) do not require advanced widgets.
Once you master Tkinter, learning PyQt or Kivy becomes much easier because you already understand the underlying principles.
10. Check Your Understanding (Quizzes)
Quiz 1: Multiple Choice
- Which Python GUI library is included with the standard Python distribution by default?
- A) PyQt
- B) wxPython
- C) Tkinter
- D) Kivy
Answer
C – Tkinter is built‑in.
- Which library is recommended if you need to develop a commercial (closed‑source) desktop application with a native look, and you want to avoid paying licensing fees?
- A) PyQt (GPL version)
- B) PySide (LGPL version)
- C) Tkinter
- D) Kivy
Answer
B – PySide uses LGPL, which allows closed‑source dynamic linking.
- Which library uses a declarative KV language to separate UI design from application logic?
- A) wxPython
- B) PyQt
- C) Kivy
- D) Tkinter
Answer
C – Kivy uses the KV language.
- Which library provides the most faithful native look on Windows, macOS, and Linux by using the platform's native widgets?
- A) Tkinter (with ttk)
- B) PyQt
- C) wxPython
- D) Kivy
Answer
C – wxPython uses native platform widgets for maximum fidelity.
- What is the name of the visual drag‑and‑drop designer that comes with PyQt/PySide?
- A) Glade
- B) Qt Designer
- C) KV Designer
- D) Tk Designer
Answer
B – Qt Designer is the official visual designer.
Quiz 2: True or False
- True / False: Tkinter cannot run on macOS – it only works on Windows.
Answer
False – Tkinter works on Windows, macOS, and Linux.
- True / False: PyQt and PySide have nearly identical APIs, but they have different licenses.
Answer
True – They are almost identical in API but differ in licensing.
- True / False: Kivy applications look exactly like native Windows applications.
Answer
False – Kivy draws its own widgets, so it does not look native.
- True / False: You need to install PyQt separately using
pip because it is not part of the standard Python library.
Answer
True – PyQt must be installed via `pip` or a package manager.
- True / False: wxPython is a good choice if you plan to publish your app on the Apple App Store for iOS.
Answer
False – wxPython does not support iOS or Android.
Quiz 3: Scenario‑Based
- You are a freelancer building a scientific data visualisation tool that needs to display complex 3D surface plots, have a rich table view for editing data, and must run on Windows and macOS with a polished, modern interface. Which library would you choose, and why?
Answer
**PyQt/PySide** – because of its support for 3D graphics (OpenGL), rich table widgets, cross‑platform capability, and professional appearance. Also, the visual designer speeds up development.
- You are teaching a 2‑hour workshop on Python programming to absolute beginners. The workshop includes a hands‑on session where students must build a simple BMI calculator with a window, a button, and a text field. Which library is the most practical choice, and why?
Answer
**Tkinter** – because it requires no installation, has a very low learning curve, and works immediately on every student's machine.
- Your company wants to build a warehouse inventory app that warehouse workers will use on Android tablets with touch screens. Workers need to tap items, swipe to confirm, and scan barcodes. Which library is most suitable, and what is the main trade‑off you must accept?
Answer
**Kivy** – because it supports Android tablets and multi‑touch gestures perfectly. The trade‑off is that the UI will *not* look like a typical Android native app; it will have Kivy's custom appearance.
Quiz 4: Matching
Match the library to its primary use case:
| Library |
Use Case |
| A. Tkinter |
1. Mobile multi‑touch game |
| B. PyQt |
2. Quick internal script for a system admin |
| C. wxPython |
3. Professional photo editing software with native UI |
| D. Kivy |
4. A Linux‑only system monitor for the GNOME desktop |
| E. PyGTK |
5. A cross‑platform CAD tool with advanced widgets |
Answer
A‑2, B‑5, C‑3, D‑1, E‑4.
11. Hands‑On Lab (In‑Class Exercises)
Exercise 1: Check Your Installed Libraries
Open a Python terminal (or a Jupyter notebook) and run the following commands one by one. Note which ones succeed and which raise ModuleNotFoundError.
import tkinter
import PyQt6
import wx
import kivy
Question: Based on your results, which library is the only one "guaranteed" to be available on any Python installation?
Answer
Only `tkinter` is guaranteed to be available, because it is part of the standard library.
Exercise 2: Compare "Hello World" Code Complexity
Write a "Hello World" GUI program in Tkinter and another in PyQt (if you have it installed). Count the number of lines of code. Discuss with a partner: which one feels more intuitive to you?
Sample comparison
Tkinter Hello World (6 lines) vs PyQt (10+ lines). Tkinter is more concise and requires less boilerplate, making it easier for beginners.
Exercise 3: Research Installation Commands
For each of the following libraries, write down the pip install command you would use:
- Tkinter (if it were not built‑in)
- PyQt5
- wxPython
- Kivy
Sample commands
- `pip install tk` (though normally not needed)
- `pip install PyQt5`
- `pip install wxPython`
- `pip install kivy`
Exercise 4: Identify the Library (Screenshot Analysis)
Your instructor will show you four screenshots of applications. Identify which library (Tkinter, PyQt, wxPython, or Kivy) was most likely used to create each, based on visual appearance. Justify your answers.
Sample reasoning
- Tkinter (classic) – grey, chunky buttons with 3D borders.
- PyQt – modern, polished, native‑looking, often with tabs and advanced widgets.
- wxPython – identical to the OS's native controls (Windows 10 buttons look like Windows 10, etc.).
- Kivy – colourful, flat, modern, with custom widgets that do not resemble the OS.
12. Homework Assignment
Objective
Demonstrate your ability to research, compare, and critically evaluate GUI libraries for a real‑world scenario. You will also reflect on the trade‑offs between ease of use and functionality.
Part A: Library Feature Matrix (10 points)
Create a table (in your submission document) with the following libraries as rows: Tkinter, PySide6, wxPython, Kivy, Dear PyGui. Use the following columns:
- License type
- Default installation method (
pip or built‑in)
- Supports Android? (Yes/No)
- Supports macOS? (Yes/No)
- Has a visual UI designer? (Yes/No)
- Can display 3D graphics natively? (Yes/No)
Fill in the table accurately using official documentation (not this tutorial alone).
Sample table (partial)
| Library | License | Install | Android | macOS | Designer | 3D |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| Tkinter | PSF | built‑in | No | Yes | No | No |
| PySide6 | LGPL | pip | Limited | Yes | Yes | Yes |
| wxPython | wxWindows | pip | No | Yes | No | No (but can use OpenGL) |
| Kivy | MIT | pip | Yes | Yes | No (KV language) | No (but can integrate) |
| Dear PyGui | MIT | pip | No | Yes | No | Yes (GPU accelerated) |
Part B: Scenario – Start‑up Company (15 points)
Scenario: A new start‑up called "EcoTrack" wants to build a desktop application for environmental data analysts. The app must:
- Run on Windows and macOS.
- Display large interactive charts (scatter plots, bar charts) with zoom and pan.
- Import/export CSV and Excel files.
- Have a clean, modern, professional look that attracts enterprise clients.
- Be developed within 6 months by a team of 5 junior Python developers.
- The start‑up plans to sell the software commercially and keep the source code closed.
Tasks:
- Recommend one library from the tutorial that you think is the best fit. Justify with at least four specific arguments (consider functionality, licensing, development speed, and learning curve).
- Recommend one library that would be a terrible fit. Explain why in at least three sentences.
- If the start‑up later decides to also release a mobile version for iPads, would your recommendation change? If so, to which library, and why?
Sample Answer
1. **PySide6** – It provides excellent charting (using Qt's QChart) and supports CSV/Excel import via Python libraries. Its LGPL license allows closed‑source commercial use without paying. The Qt Designer speeds up UI development, and junior developers can learn it with sufficient online resources. It also looks native on both Windows and macOS, which is crucial for enterprise clients.
2. **Tkinter** would be a terrible fit – it lacks built‑in charting, its appearance is outdated, and it would not give the professional look required. Adding charts would require additional libraries and extra effort.
3. Yes, the recommendation would change to **Kivy** if iPad support is needed, because Kivy is one of the few Python GUI frameworks that support iOS. The trade‑off would be that the UI would no longer be native-looking, but for mobile it might be acceptable.
Part C: Personal Reflection (5 points)
In your own words (8–10 sentences), explain why no single GUI library is "the best" for all situations. Use at least two real‑world analogies (e.g., choosing a vehicle, choosing a tool in a workshop) to illustrate your point.
Sample Answer
No single GUI library is universally best because different projects have different constraints: development time, licensing, platform support, and feature requirements. Just as you would not use a sports car to carry furniture, you would not use Kivy to build a desktop financial dashboard if you need native-looking charts. Similarly, a simple internal tool does not require the heavyweight Qt framework – Tkinter is like a handy Swiss Army knife, sufficient for many small jobs. PyQt/PySide is like a full workshop with power tools, excellent for heavy projects but overkill for a quick script. Kivy is like an amphibious vehicle – great for crossing water (mobile) but not as comfortable on the highway (desktop). The choice always depends on the specific journey you need to make.
Part D: Code Recognition (5 points)
Look at the following code snippet. Identify which library it is written for. Provide at least three clues from the code that support your identification.
from some_library import App, BoxLayout, Button, Label
class MyApp(App):
def build(self):
layout = BoxLayout(orientation='vertical')
lbl = Label(text='Click me!')
btn = Button(text='Submit')
layout.add_widget(lbl)
layout.add_widget(btn)
return layout
if __name__ == '__main__':
MyApp().run()
Answer
**Kivy** – Clues:
1. The import of `App`, `BoxLayout`, `Button`, `Label` from `some_library` resembles Kivy's import pattern (`kivy.app.App`, `kivy.uix.boxlayout.BoxLayout`, etc.).
2. The `build()` method that returns a layout is typical of Kivy's app class.
3. The use of `add_widget()` to add children to a layout is characteristic of Kivy.
4. The `.run()` method at the end is how a Kivy app is started.
Part E: Installation Troubleshooting (5 points)
You are a TA helping a student who is trying to install PyQt5 on their Windows machine. They ran pip install PyQt5 successfully, but when they try to import PyQt5 they get an error: DLL load failed: The specified module could not be found. What is the most likely cause, and how would you guide them to fix it? (Hint: Think about system dependencies.)
Answer
The most likely cause is that the required Visual C++ Redistributable (or other system DLLs) is missing. PyQt5 depends on runtime libraries that are not bundled with Python on Windows. To fix it, the student should install the latest Microsoft Visual C++ Redistributable from Microsoft's website. Alternatively, they could try installing PyQt5 via a wheel that includes all dependencies (e.g., `pip install pyqt5-tools`), or use a conda environment which handles system dependencies better. They should also check that they have the correct version for their Python architecture (32‑bit vs 64‑bit).
13. Summary of Key Terms (Glossary)
| Term |
Definition |
| Binding |
A wrapper that allows a Python program to call functions from a C/C++ library (e.g., Qt, wxWidgets). |
| Native Widget |
A UI element drawn by the operating system itself (e.g., a Windows button). |
| License |
A legal document that dictates how a library can be used, modified, and distributed (e.g., GPL, MIT, LGPL). |
| Event Loop |
The infinite loop in a GUI that waits for and dispatches events. |
| Visual Designer |
A tool that allows you to create UI layouts by dragging and dropping components, rather than coding them. |
| KV Language |
Kivy's declarative language for describing UI layouts separately from Python logic. |
| Signals & Slots |
Qt's event communication mechanism – a signal is emitted (e.g., "button clicked") and a slot (function) is connected to handle it. |
14. Further Resources for Self‑Study
- Tkinter: Official Python documentation –
tkinter module.
- PySide6: Official Qt for Python documentation (doc.qt.io/qtforpython).
- wxPython: Official wxPython website and demo applications.
- Kivy: Official Kivy documentation and the "Kivy Crash Course" video series.
- Decision Helper: "Python GUI Programming" – a curated list on the Python Wiki.
This tutorial is designed to take approximately 2.5 hours of study time, including research for the homework. After completing it, you should be able to confidently explain the strengths and weaknesses of each major Python GUI library and justify why this course prioritises Tkinter.
Previous | Tutorial index | Next