import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class MyWindow(Gtk.ApplicationWindow): def __init__(self, app): Gtk.Window.__init__(self, application=app) self.set_title("My Window") self.set_default_size(400, 300) label = Gtk.Label(label="Hello, World!") self.add(label) app = Gtk.Application() win = MyWindow(app) win.show_all() app.run(None)
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class MyWindow(Gtk.ApplicationWindow): def __init__(self, app): Gtk.Window.__init__(self, application=app) self.set_title("My Window") self.set_default_size(400, 300) 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!") app = Gtk.Application() win = MyWindow(app) win.show_all() app.run(None)This example shows how to create a window with a button widget that prints a message when clicked. The button widget connects to a callback function defined in the window class. Package library: PyGObject (Python bindings for GObject-based libraries)