Previous | Tutorial index | Next

Tutorial 2: Overview of Python Libraries for GUI Development

Learning Objectives

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

2.3 Limitations

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

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.

3.2 Key Features (Both)

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() # Starts the event loop

3.5 When to Choose PyQt/PySide

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

4.3 Limitations

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

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

5.3 Limitations

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

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

  1. Is the user non‑technical and on a desktop?

  2. Do you need a flawless native appearance on Windows/macOS?

  3. Do you need mobile (Android/iOS) support?

  4. Is your application large, complex, or requiring advanced widgets (charts, 3D)?

9. Why This Course Uses Tkinter

Despite the existence of more powerful libraries, this course focuses on Tkinter for the following reasons:

  1. Zero setup – Students can start coding immediately without struggling with installation errors.
  2. Universal availability – Works on every lab computer, regardless of operating system.
  3. Teaches core GUI concepts – Layout management, event handling, widget configuration – these concepts transfer directly to any other GUI library.
  4. Gentle learning curve – Students can concentrate on programming logic rather than fighting with a complex API.
  5. 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

  1. Which Python GUI library is included with the standard Python distribution by default?
AnswerC – Tkinter is built‑in.
  1. 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?
AnswerB – PySide uses LGPL, which allows closed‑source dynamic linking.
  1. Which library uses a declarative KV language to separate UI design from application logic?
AnswerC – Kivy uses the KV language.
  1. Which library provides the most faithful native look on Windows, macOS, and Linux by using the platform's native widgets?
AnswerC – wxPython uses native platform widgets for maximum fidelity.
  1. What is the name of the visual drag‑and‑drop designer that comes with PyQt/PySide?
AnswerB – Qt Designer is the official visual designer.

Quiz 2: True or False

  1. True / False: Tkinter cannot run on macOS – it only works on Windows.
AnswerFalse – Tkinter works on Windows, macOS, and Linux.
  1. True / False: PyQt and PySide have nearly identical APIs, but they have different licenses.
AnswerTrue – They are almost identical in API but differ in licensing.
  1. True / False: Kivy applications look exactly like native Windows applications.
AnswerFalse – Kivy draws its own widgets, so it does not look native.
  1. True / False: You need to install PyQt separately using pip because it is not part of the standard Python library.
AnswerTrue – PyQt must be installed via `pip` or a package manager.
  1. True / False: wxPython is a good choice if you plan to publish your app on the Apple App Store for iOS.
AnswerFalse – wxPython does not support iOS or Android.

Quiz 3: Scenario‑Based

  1. 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.
  1. 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.
  1. 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
AnswerA‑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 # This should always work import PyQt6 # or PySide6 – likely fails unless installed import wx # likely fails import kivy # likely fails

Question: Based on your results, which library is the only one "guaranteed" to be available on any Python installation?

AnswerOnly `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:

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:

  1. License type
  2. Default installation method (pip or built‑in)
  3. Supports Android? (Yes/No)
  4. Supports macOS? (Yes/No)
  5. Has a visual UI designer? (Yes/No)
  6. 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:

Tasks:

  1. 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).
  2. Recommend one library that would be a terrible fit. Explain why in at least three sentences.
  3. 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

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