Skip to content

Instantly share code, notes, and snippets.

@acristoffers
Created July 11, 2024 18:17
Show Gist options
  • Save acristoffers/ab2ed3b4b6e0ce67a2484c33822fc2fd to your computer and use it in GitHub Desktop.
Save acristoffers/ab2ed3b4b6e0ce67a2484c33822fc2fd to your computer and use it in GitHub Desktop.
Symbolic SVG with GTK4 in Python
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import gi
import os
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk
from gi.repository import Gio
def on_activate(app):
win = Gtk.ApplicationWindow(application=app)
pwd = os.path.dirname(os.path.abspath(__file__))
icon_path = os.path.join(pwd, "icon-symbolic.svg")
icon = Gio.Icon.new_for_string(icon_path)
img = Gtk.Image.new_from_gicon(icon)
img.set_pixel_size(512)
win.set_child(img)
win.present()
app = Gtk.Application(application_id="org.gtk.Example")
app.connect("activate", on_activate)
app.run(None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment