使用PyGObject重新打开窗口

时间:2015-06-29 13:42:15

标签: python python-3.x pygtk pygobject

代码:

=

我试图重新打开窗口,但得到:(gui.py:20607):

  

Gtk-CRITICAL **:gtk_widget_show:断言' GTK_IS_WIDGET(小部件)'   失败

     

(gui.py:20607):Gtk-CRITICAL **:gtk_label_set_markup:断言   ' GTK_IS_LABEL(标签)'失败

     

(gui.py:20607):Gtk-CRITICAL **:gtk_container_foreach:   断言' GTK_IS_CONTAINER(容器)'失败

关于对话框:

<...>
class Handler:
    <...>
    @staticmethod
    def about_destroy(*args):
        about_win.destroy()
    <...>
    @staticmethod
    def about_menu(*args):
        about_win.show_all()

builder = Gtk.Builder()
builder.add_from_file("{}/gui.glade".format(SCRIPTDIR))
builder.connect_signals(Handler())

about_win = builder.get_object("About")

main = builder.get_object("Main")
main.show_all()
<...>
Gtk.main()

1 个答案:

答案 0 :(得分:1)

我自己解决了我的问题。

我现在使用 .hide()方法代替 .destroy()。我的代码:

<...>
class Handler:
    <...>
    @staticmethod
    def about_destroy(*args):
        about_win.hide()
    <...>
    @staticmethod
    def about_menu(*args):
        about_win.show_all()

builder = Gtk.Builder()
builder.add_from_file("{}/gui.glade".format(SCRIPTDIR))
builder.connect_signals(Handler())

about_win = builder.get_object("About")

main = builder.get_object("Main")
main.show_all()
<...>
Gtk.main()