Prøve GULL - Gratis
Window of Opportunity
Linux Magazine
|#297/August 2025: Cleaning Up
Add graphics that automatically update. We show you how to build an analog clock widget with the Cairo and GTK libraries.

Last month, I covered drawing an analog clock face using the Cairo graphics library [1], [2]. While the programs in that article drew to image files, this article demonstrates how to program an analog clock drawn in a graphical user interface (GUI) window. I will also show how to make the clock automatically update, redrawing every second to simulate a ticking clock.
Because I have already covered the process of drawing a clock, this article focuses on the GUI aspect of the program. For this project, I will use the GTK [3] GUI library, because it interfaces well with Cairo and the Python language, both of which I used in the previous clock program. GTK is used from a Python program via the GObjectIntrospection [4] library; you need to ensure that you have Cairo, GTK, and GObjectintrospection installed before you start programming this project. You will also need the interface between Cairo and GObjectIntrospection in order to use Cairo with GTK. On Debian, Ubuntu, and their derivative Linux distributions, the following command will ensure everything you need is installed:
sudo apt install python3-cairo python3-gi python3-gi-cairo girl.2-gtk-3.0
This article uses GTK3, which is in long-term maintenance status, instead of the current version GTK4. Despite its age, GTK3 is still prevalent as of this writing and has had more time to mature than GTK4. Nevertheless, if you want to experiment with GTK4 and Python, install the additional GObjectIntrospection data for GTK4:
sudo apt install girl.2-gtk-4.0
A Simple GUI Window
To introduce programming with GTK, I will write a very simple program to open a window and exit the program when the user closes the window. I begin by loading GTK using GObjectIntrospection:
import gi gi.require_version ('Gtk', '3.0') from gi.repository import Gtk
Denne historien er fra #297/August 2025: Cleaning Up-utgaven av Linux Magazine.
Abonner på Magzter GOLD for å få tilgang til tusenvis av kuraterte premiumhistorier og over 9000 magasiner og aviser.
Allerede abonnent? Logg på
FLERE HISTORIER FRA Linux Magazine
Linux Magazine
Exercise Place
The GRUB 2 boot manager might seem intimidating at first glance. All the more reason to spin up a virtual playground so you can practice.
10 mins
#298/September 2025: Indie Game Studio
Linux Magazine
Terminal Mosaic
What's better than one command line? Many command lines that never die. Take the terminal to new places with Zellij.
9 mins
#298/September 2025: Indie Game Studio

Linux Magazine
MakerSpace
Build a Long-Range Sensor Network with ChirpStack Sensor Symphony
14 mins
#298/September 2025: Indie Game Studio

Linux Magazine
How Flatpak, AppImage, and Snap are changing software distribution Ship It!
Modern-day package systems solve some problems posed by classic formats like DEB and RPM. We look at Flatpak, AppImage, and Snap and describe how they differ.
12 mins
#298/September 2025: Indie Game Studio

Linux Magazine
Dashboard Delight
Simplify the chaos of self-hosted services with Homepage, a customizable dashboard with widgets that put service statistics at your fingertips.
9 mins
#298/September 2025: Indie Game Studio

Linux Magazine
MADDOG'S DOGHOUSE
Free software, and the FOSS community, can help technology students get the education they desire in Brazil and elsewhere.
3 mins
#298/September 2025: Indie Game Studio

Linux Magazine
Rethinking the Terminal
The Warp AI agent takes the guesswork out of working at the command line. We show you how to build a simple website with one prompt.
4 mins
#298/September 2025: Indie Game Studio
Linux Magazine
Just in Time
Just is a command runner that lets you define project-specific tasks in a declarative justfile.
7 mins
#298/September 2025: Indie Game Studio

Linux Magazine
The Watcher
This versatile security app checks for vulnerabilities, watches logs, and acts as a single interface for other tools.
7 mins
#298/September 2025: Indie Game Studio

Linux Magazine
NO INTERNETREQUIRED
This new utility lets you update a system that is notconnected to the Internet.
4 mins
#298/September 2025: Indie Game Studio
Listen
Translate
Change font size