| 1 |
import gi |
| 2 |
|
| 3 |
gi.require_version("Gtk", "4.0") |
| 4 |
from gi.repository import Gtk |
| 5 |
|
| 6 |
|
| 7 |
class GridWindow(Gtk.ApplicationWindow): |
| 8 |
def __init__(self, **kargs): |
| 9 |
super().__init__(**kargs, title="Grid Example") |
| 10 |
|
| 11 |
button1 = Gtk.Button(label="Button 1") |
| 12 |
button2 = Gtk.Button(label="Button 2") |
| 13 |
button3 = Gtk.Button(label="Button 3") |
| 14 |
button4 = Gtk.Button(label="Button 4") |
| 15 |
button5 = Gtk.Button(label="Button 5") |
| 16 |
button6 = Gtk.Button(label="Button 6") |
| 17 |
|
| 18 |
grid = Gtk.Grid() |
| 19 |
grid.attach(button1, 0, 0, 1, 1) |
| 20 |
grid.attach(button2, 1, 0, 2, 1) |
| 21 |
grid.attach_next_to(button3, button1, Gtk.PositionType.BOTTOM, 1, 2) |
| 22 |
grid.attach_next_to(button4, button3, Gtk.PositionType.RIGHT, 2, 1) |
| 23 |
grid.attach(button5, 1, 2, 1, 1) |
| 24 |
grid.attach_next_to(button6, button5, Gtk.PositionType.RIGHT, 1, 1) |
| 25 |
|
| 26 |
self.set_child(grid) |
| 27 |
|
| 28 |
|
| 29 |
def on_activate(app): |
| 30 |
# Create window |
| 31 |
win = GridWindow(application=app) |
| 32 |
win.present() |
| 33 |
|
| 34 |
|
| 35 |
app = Gtk.Application(application_id="com.example.App") |
| 36 |
app.connect("activate", on_activate) |
| 37 |
|
| 38 |
app.run(None) |