没有Gtk.main(),GTK3中的python解释器中不会显示窗口 [英] Window doesn't show in python interpreter in GTK3 without Gtk.main()
问题描述
在GTK2中,我喜欢即时"在解释器(ipython或纯python)中构建gui,并实时观察到这样的变化:
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.
我之所以改用Gtk3,部分是因为这是未来,部分是因为我有时会使用Glade,而现在的Glade只是Gtk3.使用GTK3进行相同操作时,不显示窗口:
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()
A,最后一行之后没有窗口.直到:
Alas, no window after that last line. It won't show until:
>>> Gtk.main()
我什至尝试:
>>> win.show_now()
什么都没做.
有什么想法如何在GTK3中实时构建?
Any ideas how to build in real time in GTK3?
谢谢
纳尼
推荐答案
我尝试使用以下一种方法处理未决事件:
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.
或者,如果您正在开发Gtk应用程序,则pdb.set_trace
仍然可以正常工作,并且如果需要的话,还可以让您调试回调.
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.
这篇关于没有Gtk.main(),GTK3中的python解释器中不会显示窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!