Overview
GTK+ is a widely used, robust multi-platform toolkit for creating graphical user interfaces. It powers many Linux desktops and offers cross-platform support for Linux, Windows, and macOS. With PyGObject, Python developers can utilize GTK+ for building dynamic GUIs.
Key features
- Rich set of modern and traditional UI elements
- Cross-platform capabilities
- Accessible and internationalized development
- Native look and feel on all platforms
- Highly customizable and scalable
Common use cases
- Desktop applications on Linux, Windows, and macOS
- Tools requiring rich graphic elements
- Enterprise software with GUI components
- Cross-platform development targeting different operating systems
- Embedded systems with GUI interfaces
Installation
# Install GTK+ development libraries and PyGObject bindings # On Debian-based systems, you might use: sudo apt-get install python3-gi python3-gi-cairo gir1.2-gtk-3.0 # Ensure that you have installed GTK+ dependencies for your platform
Example
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
super().__init__(title="Hello GTK+")
self.set_default_size(200, 100)
button = Gtk.Button(label="Click Me")
button.connect("clicked", self.on_button_clicked)
self.add(button)
def on_button_clicked(self, widget):
print("Hello World")
win = MyWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()