Window doesn't show in python interpreter in GTK3 without Gtk.main()
-
05-12-2019 - |
質問
In GTK2, I enjoyed building a gui in the interpreter (ipython or plain python) "on the fly" and seeing the changes in real time like this:
>>> import gtk
>>> win = gtk.Window()
>>> win.connect('delete-event', gtk.main_quit)
10L
>>> win.show_all()
Which will result in showing a window to which I could add objects.
I'm changing to Gtk3 in part because it is the future and in part because I sometimes use Glade which now is only Gtk3. In doing the same with GTK3 DOESN'T show the window:
>>> from gi.repository import Gtk
>>> win = Gtk.Window()
>>> win.connect('delete-event', Gtk.main_quit)
13L
>>> win.show_all()
Alas, no window after that last line. It won't show until:
>>> Gtk.main()
I even tried:
>>> win.show_now()
Which did nothing.
Any ideas how to build in real time in GTK3?
Thanks,
Narnie
解決
I tried to process pending events with the following one-liner:
>>> while Gtk.events_pending(): Gtk.main_iteration()
and it looks to have the same behaviour. It's not so convenient, but you can still do some work in the interpreter.
Alternatively, if you're developing a Gtk application, pdb.set_trace
will still work and let you debug callbacks if that's what you're looking for.