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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="512mm"
height="288mm"
viewBox="0 0 512 288"
version="1.1"
id="svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<g
id="tile-center"
style="image-rendering:optimizeQuality">
<rect
style="fill:#BEBEBE"
id="window"
width="149"
height="120"
x="181"
y="84"
ry="8" />
</g>
</svg>
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