Blame platform-demos/C/samples/grid.py

Packit 1470ea
from gi.repository import Gtk
Packit 1470ea
import sys
Packit 1470ea
Packit 1470ea
Packit 1470ea
class MyWindow(Gtk.ApplicationWindow):
Packit 1470ea
Packit 1470ea
    def __init__(self, app):
Packit 1470ea
        Gtk.Window.__init__(self, title="Grid Example", application=app)
Packit 1470ea
Packit 1470ea
        # three labels
Packit 1470ea
        label_top_left = Gtk.Label(label="This is Top Left")
Packit 1470ea
        label_top_right = Gtk.Label(label="This is Top Right")
Packit 1470ea
        label_bottom = Gtk.Label(label="This is Bottom")
Packit 1470ea
Packit 1470ea
        # a grid
Packit 1470ea
        grid = Gtk.Grid()
Packit 1470ea
Packit 1470ea
        # some space between the columns of the grid
Packit 1470ea
        grid.set_column_spacing(20)
Packit 1470ea
Packit 1470ea
        # in the grid:
Packit 1470ea
        # attach the first label in the top left corner
Packit 1470ea
        grid.attach(label_top_left, 0, 0, 1, 1)
Packit 1470ea
        # attach the second label
Packit 1470ea
        grid.attach(label_top_right, 1, 0, 1, 1)
Packit 1470ea
        # attach the third label below the first label
Packit 1470ea
        grid.attach_next_to(
Packit 1470ea
            label_bottom, label_top_left, Gtk.PositionType.BOTTOM, 2, 1)
Packit 1470ea
Packit 1470ea
        # add the grid to the window
Packit 1470ea
        self.add(grid)
Packit 1470ea
Packit 1470ea
Packit 1470ea
class MyApplication(Gtk.Application):
Packit 1470ea
Packit 1470ea
    def __init__(self):
Packit 1470ea
        Gtk.Application.__init__(self)
Packit 1470ea
Packit 1470ea
    def do_activate(self):
Packit 1470ea
        win = MyWindow(self)
Packit 1470ea
        win.show_all()
Packit 1470ea
Packit 1470ea
app = MyApplication()
Packit 1470ea
exit_status = app.run(sys.argv)
Packit 1470ea
sys.exit(exit_status)