File: gui-gtk4.py

package info (click to toggle)
ipython 8.35.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,696 kB
  • sloc: python: 42,461; sh: 376; makefile: 243
file content (37 lines) | stat: -rw-r--r-- 716 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
"""Simple Gtk example to manually test event loop integration.

This is meant to run tests manually in ipython as:

In [1]: %gui gtk4

In [2]: %run gui-gtk4.py
"""

import gi

gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, GLib  # noqa


def hello_world(widget, data=None):
    print("Hello World")


def close_request_cb(widget, data=None):
    global running
    running = False


running = True
window = Gtk.Window()
window.connect("close-request", close_request_cb)
button = Gtk.Button(label="Hello World")
button.connect("clicked", hello_world, None)

window.set_child(button)
window.show()

context = GLib.MainContext.default()
while running:
    context.iteration(True)