Created
May 17, 2024 16:14
-
-
Save olumide-x/d0d28c9745250946ef54a69c70ac7502 to your computer and use it in GitHub Desktop.
Sample GTK Python application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python3 | |
# Based on https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html#extended-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 World") | |
self.button = Gtk.Button(label="Click Here") | |
self.button.connect("clicked", self.on_button_clicked) | |
self.button.get_accessible().set_name("MyButton") | |
self.add(self.button) | |
def on_button_clicked(self, widget): | |
print("Hello World") | |
Gtk.main_quit() | |
win = MyWindow() | |
win.connect("destroy", Gtk.main_quit) | |
win.show_all() | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment