-
Notifications
You must be signed in to change notification settings - Fork 34
/
part3.py
30 lines (24 loc) · 930 Bytes
/
part3.py
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
import sys
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw
class MyApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
# Create a Builder
builder = Gtk.Builder()
builder.add_from_file("test.ui")
# Obtain the button widget and connect it to a function
button = builder.get_object("button1")
button.connect("clicked", self.hello)
# Obtain and show the main window
self.win = builder.get_object("main_window")
self.win.set_application(self) # Application will close once it no longer has active windows attached to it
self.win.present()
def hello(self, button):
print("Hello")
app = MyApp(application_id="com.example.GtkApplication")
app.run(sys.argv)