| 1 |
import gi |
| 2 |
|
| 3 |
gi.require_version("Gtk", "4.0") |
| 4 |
from gi.repository import Gtk |
| 5 |
|
| 6 |
|
| 7 |
class ButtonWindow(Gtk.ApplicationWindow): |
| 8 |
def __init__(self, **kargs): |
| 9 |
super().__init__(**kargs, title="Button Demo") |
| 10 |
|
| 11 |
hbox = Gtk.Box(spacing=6) |
| 12 |
self.set_child(hbox) |
| 13 |
|
| 14 |
button = Gtk.Button.new_with_label("Click Me") |
| 15 |
button.connect("clicked", self.on_click_me_clicked) |
| 16 |
hbox.append(button) |
| 17 |
|
| 18 |
button = Gtk.Button.new_with_mnemonic("_Open") |
| 19 |
button.connect("clicked", self.on_open_clicked) |
| 20 |
hbox.append(button) |
| 21 |
|
| 22 |
button = Gtk.Button.new_with_mnemonic("_Close") |
| 23 |
button.connect("clicked", self.on_close_clicked) |
| 24 |
hbox.append(button) |
| 25 |
|
| 26 |
def on_click_me_clicked(self, _button): |
| 27 |
print("[Click me] button was clicked") |
| 28 |
|
| 29 |
def on_open_clicked(self, _button): |
| 30 |
print("[Open] button was clicked") |
| 31 |
|
| 32 |
def on_close_clicked(self, _button): |
| 33 |
print("Closing application") |
| 34 |
self.close() |
| 35 |
|
| 36 |
|
| 37 |
def on_activate(app): |
| 38 |
win = ButtonWindow(application=app) |
| 39 |
win.present() |
| 40 |
|
| 41 |
|
| 42 |
app = Gtk.Application(application_id="com.example.App") |
| 43 |
app.connect("activate", on_activate) |
| 44 |
|
| 45 |
app.run(None) |