best python gui library on raspberry pi

The Best Python GUI Libraries for Raspberry Pi to Try Out

Creating user interfaces in Python for your Raspberry Pi projects is not as complicated as you might think, and it will highly improve the end-user experience (even if it’s only you). I recently tested a few Python libraries that allow you to create a GUI (Graphical User Interface), so I will share my favorites in this article.

Overall, PyQT and Tkinter are the most popular Python libraries to create interfaces on Raspberry Pi. They are both rather simple to use and include the essential features expected for that kind of project.

But other options can be considered if you need something more advanced. I’ll even suggest one that you might already know but wouldn’t expect in this list.

By the way, if you get overwhelmed as soon as Python is required for a project, I recommend checking out my e-book “Master Python on Raspberry Pi“. It will guide you step-by-step to learn the essential concepts (and only the essential concepts) required to achieve any project in the future. Raspberry Pi without Python is like a car without an engine, you miss all the fun parts. Get 10% off by downloading it today!

PyQT: A great choice for most projects

PyQt is a library that can be used to create GUI applications with Python. On Raspberry Pi OS, it’s available in the default repository and can be installed via the package manager (APT).

If you’re looking for something basic with a minimalist design, this is probably the first one I’d recommend testing out.

In most cases, Raspberry Pi applications don’t have a ton of users (we are often the only user), so we don’t need anything fancy. A few buttons, maybe some input fields, and we are good to go. As you’ll see in the example below, PyQT is perfect for that.

Installation

There are two ways to get PyQt on Raspberry Pi: you can either use APT to get the version from the repository or use PIP to install the latest version available.

If you are using Raspberry Pi OS, using APT is probably your best option:
sudo apt update
sudo apt install python3-pyqt5

On other operating systems, or if you absolutely need the latest version, you can use PIP to install this library on the Raspberry Pi.

Example

Once PyQT is installed, you can add it to your scripts. The base syntax is not very intuitive, but it’s always the same, so you’ll get used to it.

You’ll start by importing the elements you need from the library with something like:
from PyQt5.QtWidgets import QApplication, QMainWindow

Then, you can create the main window for your application with these lines:
app = QApplication([])
win = QMainWindow()
win.show()

And finally, add elements to your main window, with functions looking like:
label = QLabel("This is a text", win)
label.move(20, 0)

Grab my Python cheat sheet!
If like me, you always mix the languages syntax, download my cheat sheet for Python here!
Download now

Here is what a more complete example will look like:

I explain everything in detail, with a step-by-step guide to create your first interface with PyQT. I highly recommend checking the full article if you haven’t tried it.

Overall, I think the syntax could be simpler, but I like the fact that it is always the same pattern: create an element, place it on the window (with coordinates), move to the next element, etc.

Tkinter: The old-school way of creating GUI

Tkinter is another popular Python library used to create graphical user interfaces (GUIs). It’s often preinstalled on Raspberry Pi, so you can start right away.

I have less experience with it than with PyQT, but from the few tests I did, I can already say that I like it. It’s pretty easy to get started once you have found the main functions. It might even be more straightforward than PyQT.

Installation

Anyway, if you already have Python installed on your Raspberry Pi, there is a good chance that Tkinter is already installed too.

If you have any doubts, you can try installing it with:
sudo apt install python3-tk

Once done, you can import it into any of your scripts by adding this line at the beginning:
import tkinter

Example

If we take the same example as with PyQT, you’ll create a new screen for your app with:
window = tk.Tk()

You can obviously customize it the way you want, like by fixing the size, as in my full example below.

And then it’s the same idea, you create widgets and place them on the screen. For example, adding text will look like:
text = tk.label(window, text="Hello world")
text.pack()

Here is a full example, with text and a button. The button will call a custom function to run any action you want.

And here is the complete code that you can copy/paste if you want to try it.

import tkinter as tk

#Def callback
def button_call():
    print("Debug button click")

window = tk.Tk()
window.geometry('300x200')

#Write text
text = tk.Label(window, text= "Hi RaspberryTips")
text.pack()

#Create button
button = tk.Button(window, text= "Click here", bd = '5', command= button_call)
button.pack(side = 'top')

window.mainloop()

Overall, PyQt and Tkinter are excellent choices. Pick the one you’re most comfortable with and you should be fine. In my screenshots, you can see that PyQt respects the current theme, while Tkinter is a bit rawer, with an old-school design. So, maybe PyQt is better for that, but that’s anecdotal.

CustomTkinter: Almost the same, but better

CustomTkinter is another Python library to build GUIs, based on Tkinter, but allows you to add more modern and customizable widgets. If you like Tkinter, but don’t like the design of your app, switching to CustomTkinter is probably your next move.

You’ll find a lot of similarities with Tkinter, you’ll even need it installed for some features. There are just more options. A picture from their GitHub page will give you a better idea:

Here are a few features available in CustomTkinter:

  • Create applications with themes (“light” or “dark” mode, for example).
  • Button with images.
  • Scrollable frames.
  • Theme can be adjusted to the system appearance automatically.
  • Includes a map widget.
  • Etc.

I recommend checking their GitHub page for more examples (they have a few videos too, so you can see it in action). But basically, it’s Tkinter but prettier :-).

Installation

Unlike the two first options, you need to install CustomTkinter with PIP, as it’s not available with APT.

If PIP is up-to-date, you can install it with:
pip3 install customtkinter

Grab my Python cheat sheet!
If like me, you always mix the languages syntax, download my cheat sheet for Python here!
Download now

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips.

Example

And if we take the same example again, you’ll quickly see the difference in the result on this screenshot:

Even if we have almost the same number of lines, the end result is way better, with a dark theme, a nicer font and a blue button. Nothing like the old-school app we got with the previous libraries.

In the code, we use almost the same functions:

  • CTkLabel() instead of Label() to create the text, same thing for the button.
  • place() instead of pack() to put it on the screen.
  • And note the set_appearance_mode() at the beginning to use the dark theme.

Here is the full code I use for this test:

import tkinter as tk
import customtkinter as ctk

ctk.set_appearance_mode("dark")

#Def callback
def button_call():
    print("Debug button click")

window = ctk.CTk()
window.geometry('300x200')

#Write text
text = ctk.CTkLabel(window, text= "Hi RaspberryTips")
text.place(relx=0.5, rely=0.4, anchor=tk.CENTER)

#Create button
button = ctk.CTkButton(window, text="Click here", command=button_call)
button.place(relx=0.5, rely=0.6, anchor=tk.CENTER)

window.mainloop()

The issue with this library is that it relies on a smaller team of developers, with a smaller community of users. But for personal projects (like most Raspberry Pi projects), I think it’s great. You’ll get better-looking interfaces without having to write much more complicated things.

You should at least give it a try, especially if you already know the basics of Tkinter.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Kivy: For advanced projects

Kivy is another library to create a user interface that often comes when building projects with a Raspberry Pi.

As with other alternatives (PyQt, Tkinter, etc.), Kivy allows you to build a visual interface for your project. Maybe it’s a button to click to open the garage door instead of a random script you run manually, or a sensor value that is displayed in real-time inside the app.

Kivy is like the ultimate library to create GUIs, but it’s perhaps more for professional projects. It’s modern. You can build cross-platform applications, with advanced features like multitouch or gesture-based interfaces.

The main issue is that it’s way harder to get started than with the previous options. Even the simplest examples in their documentation are built with object-oriented programming (creating new classes, using inheritance, etc.). It might quickly become a nightmare for Python beginners.

Installation

Kivy is not installed by default on Raspberry Pi OS and is not available in the default repository. You first need to install a bunch of dependencies with APT:
sudo apt update
sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev

And you can then use PIP to install Kivy itself:
pip install --upgrade pip setuptools virtualenv
pip install "kivy[base]" kivy_examples --no-binary kivy

You can find my full tutorial about Kivy on Raspberry Pi here (introduction, installation and examples).

Example

I won’t go into as many details as with the previous libraries, but I still want to show you a basic example with Kivy here.

Even for something elementary (text + button), the code is already over 30 lines long, and you need to define new classes and functions.

It looks like this:

As you can see, I created two rows for my two widgets, but it doesn’t look that natural if you keep the default options. Every is customizable, which is great, but everything has to be customized to make it look as you want, which can sometimes seem like a waste of time.

Anyway, try it if you are interested in building an app for the public, but I guess it’s generally not the best option for small Raspberry Pi projects.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

PyGame: The non-traditional challenger

This is my bonus suggestion for you. If you already know PyGame, you don’t necessarily need to install and learn a new Python library to create simple user interfaces.

Pygame is a Python library that is included by default on Raspberry Pi OS and can be used to create video games. It includes functions to create 2D games with graphics, audio and events handling.

So, even if the main goal of Pygame is to create video games, the library can also be used to generate all kinds of graphic interfaces. Let me explain.

Installation

On Raspberry Pi OS, Pygame is installed by default, so you have nothing to do.

If you are using another distribution, you can probably install it with:
sudo apt install python3-pygame

Or with PIP:
pip3 install pygame

💰 Make Money Sharing Your Raspberry Pi Expertise!
Help others navigate the world of Raspberry Pi with your insights.
Become a RaspberryTips Contributor!

Example

Once installed, using it is very similar to the previous libraries I introduced.

You’ll create a new window, and can place elements on it.

Here is the code to create an empty window:

import pygame

#Initalize Pygame
pygame.init()

#Create Window with custom title
pygame.display.set_mode((400, 200))
pygame.display.set_caption("Hello World")

Then, a bunch of functions are available, to add text, shapes and images to your window. In my tutorial about Pygame on Raspberry Pi, I show you how to create a button, even if it’s not necessarily built for this:

As you can draw a rectangle, add text and capture the mouse events (clicks and position), you can basically create buttons with it.

I know, it’s not traditional, but I just wanted to include Pygame in this article, as I feel in some cases it might be a decent alternative, especially if you already know how to use it, or need something specific (images, events capture, etc.).

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts