Hi all,
I am currently getting into developing GUIs with Python, GTK4 and libadwaita.
So far, my experience has been quite nice, but now I am hitting a problem:
When I create a AdwDialog
, I can open it once, but if I close it and try to reopen it I get the following Error message:
(python3:45276): Gtk-CRITICAL **: 09:46:38.651: gtk_window_present: assertion 'GTK_IS_WINDOW (window)' failed
Here’s a minimal (non-) working example for this behavior:
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw
class DemoWindow(Gtk.ApplicationWindow):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.set_title("Dialog Example")
self.set_default_size(200, 100)
self.dialog = Adw.Dialog(title="Dialog Example", parent=self)
self.closebtn = Gtk.Button(label="Close")
self.closebtn.connect("clicked", self.on_close_clicked)
self.dialog.set_child(self.closebtn)
button = Gtk.Button(label="Open Dialog")
button.connect("clicked", self.on_button_clicked)
self.set_child(button)
def on_button_clicked(self, button):
self.dialog.present(self.get_root())
def on_close_clicked(self, button):
self.dialog.close()
class DemoApp(Adw.Application):
def __init__(self):
super().__init__(application_id="org.example.demoapp")
self.connect("activate", self.on_activate)
def on_activate(self, app):
self.win = DemoWindow(application=app)
self.win.present()
if __name__ == "__main__":
DemoApp().run()
What am I doing wrong? Greatly appreciate your help
- Jens