Reputation: 8951
I create a GTK4 Window from an XML file via Python. When I run the code, the window actually pops up very briefly (and all controls are there as expected), but then closes immediately. I assume there is something missing in my code, but I can't figure out what it is from the documentation.
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):
builder = Gtk.Builder()
builder.add_from_file("main.glade")
self.win = builder.get_object("window")
self.win.present()
app = MyApp(application_id="com.example.GtkApplication")
app.run(sys.argv)
Upvotes: 0
Views: 368
Reputation: 8951
Fixed it :-)
The solution is a simple one-liner:
self.win.set_application(app)
Upvotes: 0