app.py:
Code: Alles auswählen
import gi, sys
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):
app.add_window(win)
win.present()
def onButtonPressed(self, button):
print("Kukuk!")
builder = Gtk.Builder.new_from_file('app.ui')
win = builder.get_object("window1")
app = MyApp(application_id=None)
print("MyApp:",dir(app))
app.run(sys.argv)
Code: Alles auswählen
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="4.6"/>
<object class="GtkApplicationWindow" id = "window1">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Application</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="onButtonPressed" swapped="no"/>
</object>
</child>
</object>
</interface>
Code: Alles auswählen
(process:10943): Gtk-ERROR **: 19:13:58.835: failed to add UI from file application.ui: No function named `onButtonPressed`.
Trace/breakpoint trap (core dumped)
![Geek :geek:](./images/smilies/icon_geek.gif)