Debian Codegraph @

docs/tutorials/gtk4/examples/layout_box.py

raw
1 import gi
2
3 gi.require_version("Gtk", "4.0")
4 from gi.repository import Gtk
5
6
7 class MyWindow(Gtk.ApplicationWindow):
8 def __init__(self, **kargs):
9 super().__init__(**kargs, title="Hello World")
10
11 box = Gtk.Box(spacing=6)
12 self.set_child(box)
13
14 button1 = Gtk.Button(label="Hello")
15 button1.connect("clicked", self.on_button1_clicked)
16 box.append(button1)
17
18 button2 = Gtk.Button(label="Goodbye")
19 button2.props.hexpand = True
20 button2.connect("clicked", self.on_button2_clicked)
21 box.append(button2)
22
23 def on_button1_clicked(self, _widget):
24 pass
25
26 def on_button2_clicked(self, _widget):
27 pass
28
29
30 def on_activate(app):
31 # Create window
32 win = MyWindow(application=app)
33 win.present()
34
35
36 app = Gtk.Application(application_id="com.example.App")
37 app.connect("activate", on_activate)
38
39 app.run(None)