mirror of
https://github.com/Taiko2k/GTK4PythonTutorial.git
synced 2026-01-04 10:20:12 +01:00
add xml section
This commit is contained in:
30
part3.py
Normal file
30
part3.py
Normal file
@@ -0,0 +1,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)
|
||||
Reference in New Issue
Block a user