Skip to content
Tutorials Center
My learning

Topics

Lesson 92 of 149 ยท Beyond the Basics

Python GUI Frameworks: Kivy, PyQt and Streamlit

Compare Python GUI frameworks. See Kivy, PySide6/PyQt, wxPython and Streamlit code side by side, learn signals and the rerun model, and pick the right toolkit.

You met tkinter, the toolkit that ships with Python. It is a fine start, but it is not the only choice, and for some projects it isn't the best one. Maybe you want an app that looks native on every desktop, a touch interface for a phone, or a data dashboard that colleagues open in a browser tab without installing anything. Python has mature frameworks for each of these, and they differ in their mental models more than in their syntax.

In this lesson you'll tour the four you are most likely to meet: Qt (through PySide6 or PyQt6), wxPython, Kivy and Streamlit. You'll see a tiny program in each, learn the two ideas that explain how they work (signals and callbacks versus a "rerun the script" model), and get a checklist for choosing between them.

What runs here and what doesn't. These frameworks need a screen (or, for Streamlit, a web server), so their code is read-only. The live examples run plain Python that models the concepts: a UI-independent core, Qt-style signals, and Streamlit's rerun cycle. Install each framework on your own computer with pip, ideally in a virtual environment.

The one-minute comparison

Framework Install Model Strengths Watch out for
tkinter built in widgets + event loop zero install, simple dated look, few widgets
PySide6 / PyQt6 pip install PySide6 widgets + signals and slots huge widget set, Designer tool, professional desktop apps license: PySide6 is LGPL, PyQt6 is GPL or paid
wxPython pip install wxPython native widgets + event binding real native look on each OS smaller community, heavier installs
Kivy pip install kivy widgets + .kv layout language, touch-first same code on desktop, Android, iOS non-native look, packaging with Buildozer
Streamlit pip install streamlit web page, script reruns on each interaction dashboards in a few lines, great for data and ML demos not a desktop app, limited layout control

Other options worth knowing: Flet and NiceGUI (apps built from Python code and shown in the browser or a desktop shell), Toga (native widgets, from the BeeWare project), customtkinter (a modern skin for tkinter), Dear PyGui (fast, GPU-drawn tools), Gradio (quick demos for machine learning models), Textual (rich terminal user interfaces) and Dash (web dashboards, a Plotly project).

Qt with PySide6 or PyQt6

Qt is the professional-grade toolkit behind apps such as VLC and many engineering tools. Python gets it through two nearly identical bindings: PySide6, the official one from the Qt project (LGPL license), and PyQt6 (GPL or commercial). Code is almost the same; only the imports differ.

Python
import sys
from PySide6.QtWidgets import QApplication, QLabel, QPushButton, QVBoxLayout, QWidget

class CounterWindow(QWidget):
    def __init__(self) -> None:
        super().__init__()
        self.setWindowTitle("Counter")
        self.count = 0

        self.label = QLabel("Clicked 0 times")
        button = QPushButton("Click me")
        button.clicked.connect(self.on_click)      # connect a signal to a slot

        layout = QVBoxLayout(self)
        layout.addWidget(self.label)
        layout.addWidget(button)

    def on_click(self) -> None:
        self.count += 1
        self.label.setText(f"Clicked {self.count} times")

app = QApplication(sys.argv)
window = CounterWindow()
window.show()
sys.exit(app.exec())                               # run the event loop

The key idea in Qt is signals and slots. A widget emits a signal when something happens (clicked, textChanged, valueChanged), and you connect it to any number of functions called slots. The button doesn't know who is listening, and the listener doesn't poll the button. You'll find the same idea in most GUI toolkits under other names (callbacks, observers, event handlers). Here is a tiny version you can run:

Python Signals and slots in 20 lines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

One signal drove three unrelated listeners, and nothing was emitted for the repeated value. Qt also provides big pieces that tkinter lacks: table and tree views backed by data models, dock windows, a drawing system, networking, multimedia, and Qt Designer, a drag-and-drop editor whose .ui files you load from Python. Run slow work in a QThread or thread pool, never inside a slot, for the same reason as in tkinter: the event loop must stay free.

wxPython

wxPython wraps the native widgets of each operating system, so a window looks like a Windows app on Windows and a Cocoa app on macOS. The structure is familiar: an app object, a frame, widgets, and event binding.

Python
import wx

class CounterFrame(wx.Frame):
    def __init__(self) -> None:
        super().__init__(None, title="Counter", size=(280, 140))
        self.count = 0
        panel = wx.Panel(self)
        self.label = wx.StaticText(panel, label="Clicked 0 times", pos=(20, 20))
        button = wx.Button(panel, label="Click me", pos=(20, 55))
        button.Bind(wx.EVT_BUTTON, self.on_click)      # bind an event to a handler

    def on_click(self, event: wx.CommandEvent) -> None:
        self.count += 1
        self.label.SetLabel(f"Clicked {self.count} times")

app = wx.App()
CounterFrame().Show()
app.MainLoop()

Choose wxPython when a truly native appearance matters and you like a conventional event-driven style. Note that it uses its own naming style (SetLabel, EVT_BUTTON) rather than Python's snake_case.

Kivy

Kivy is built for touch and for shipping to phones as well as desktops. It draws its own widgets with the graphics card, so the look is the same everywhere but isn't native. Its signature feature is the kv language, a small declarative language for describing layouts and bindings, kept separate from the Python logic.

Python
from kivy.app import App
from kivy.lang import Builder

KV = """
BoxLayout:
    orientation: "vertical"
    padding: 20
    spacing: 10
    Label:
        id: counter
        text: "Clicked 0 times"
    Button:
        text: "Click me"
        on_release: app.click()
"""

class CounterApp(App):
    count = 0

    def build(self):
        return Builder.load_string(KV)

    def click(self) -> None:
        self.count += 1
        self.root.ids.counter.text = f"Clicked {self.count} times"

CounterApp().run()

In kv, properties such as text are observable, and an expression like text: str(app.count) updates automatically when count changes: you describe what the screen is and Kivy keeps it in sync. For phones, the Buildozer tool packages a Kivy app as an Android APK. Choose Kivy for touch-first or cross-platform mobile and kiosk apps; skip it when you need standard desktop controls such as native file pickers and menus.

Streamlit: a different model

Streamlit throws away callbacks entirely. You write a normal top-to-bottom script. Widgets are function calls that return their current value, and Streamlit shows the result in a browser:

Python
import streamlit as st

st.title("Tip calculator")

bill = st.number_input("Bill amount", min_value=0.0, value=50.0)
percent = st.slider("Tip percent", 0, 30, 15)

st.write(f"Tip: {bill * percent / 100:.2f}")
st.metric("Total", f"{bill * (1 + percent / 100):.2f}")

Run it with streamlit run app.py; Streamlit opens a local web page. The rule that explains everything: every time the user interacts with a widget, Streamlit runs the whole script again from the top. On each run, st.slider(...) returns the position the user chose. There are no handlers: you just write percent * bill where you need it. Anything that must survive between runs goes in st.session_state, and slow calculations or downloads should be wrapped in st.cache_data so a rerun doesn't repeat them. Here is a model of that cycle:

Python Streamlit's rerun model, simulated

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The slow data loaded only once because of the cache, while session_state counted every run. Streamlit shines for dashboards, data exploration and machine-learning demos: no HTML, CSS or JavaScript, and a shareable web app in an afternoon. The cost is control. You don't decide exactly where things go, and a complex multi-step app with lots of state takes care. For a more conventional web app, see web development or FastAPI.

How to choose

Ask these questions in order:

  1. Is it for yourself or a small team, and does it analyze data? Use Streamlit (or Gradio for model demos). It is the fastest path from script to app.
  2. Does it need to run on phones or tablets? Use Kivy, or build a web app that works on mobile.
  3. Is it a serious desktop application with many windows, tables and menus? Use Qt (PySide6 if licensing matters to you).
  4. Does it need a perfectly native look? Consider wxPython (or Toga).
  5. Is it a small utility with a few buttons? tkinter is enough and has nothing to install.

Whichever you choose, the same architecture advice applies. Keep your logic in plain classes that know nothing about windows, and let the GUI be thin glue that calls them. That is what lets you test the logic with pytest and switch toolkits later:

Python One core, many front ends

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The same Counter could sit behind a Qt window, a Kivy screen or a Streamlit page: only the thin view code changes.

Common mistakes

  • Starting with the biggest framework. Qt has a long learning curve. Build the logic first, and pick the toolkit when you know the requirements.
  • Blocking the event loop with downloads or heavy calculations in any desktop framework. Use threads or the framework's worker tools.
  • Mixing PySide6 and PyQt6 imports in one program. They are separate packages; pick one.
  • Expecting Streamlit state to persist. Plain variables reset on every rerun; use st.session_state and caching.
  • Forgetting licenses. PyQt6 is GPL unless you buy a commercial license; check before shipping closed-source software.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is a Qt signal?

    Signals decouple the sender from its listeners. The widget emits clicked or valueChanged without knowing who responds.
  2. 2. In a Streamlit app, a user moves a slider. What happens?

    Streamlit reruns the script after each interaction. Plain variables reset, so use st.session_state for state and st.cache_data for expensive work.
  3. 3. Which framework is the best fit for a touch-first app that also needs to run on Android?

    Kivy is designed for touch interfaces and can be packaged for Android and iOS. wxPython and tkinter target desktops, and Textual targets terminals.
  4. 4. Why keep application logic in classes that don't import any GUI framework?

    A UI-independent core can be tested with ordinary unit tests and reused behind a different front end.
  5. 5. What is the main licensing difference between PySide6 and PyQt6?

    PySide6 is the official binding under the LGPL, which is easier for closed-source apps. PyQt6 requires GPL compliance or a commercial license.

Summary

  • Python has several GUI toolkits with different strengths: tkinter (built in), Qt (PySide6/PyQt6), wxPython (native look), Kivy (touch and mobile) and Streamlit (data apps in the browser).
  • Desktop toolkits are event-driven: Qt uses signals and slots, wxPython binds events, and Kivy uses properties and the kv language.
  • Streamlit reruns your whole script after every interaction; use st.session_state for state and st.cache_data for slow work.
  • Choose by need: Streamlit for dashboards, Kivy for mobile, Qt for large desktop apps, wxPython for native look, tkinter for tiny utilities.
  • Keep logic in framework-free classes so it can be tested and reused.

Next: Writing Pythonic Code, a tour of the idioms that make Python code clear and natural.