使用 PyGObject 重新打开 window

Reopen window using PyGObject

代码:

<...>
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()

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

Gtk-CRITICAL **: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

(gui.py:20607): Gtk-CRITICAL **: gtk_label_set_markup: assertion 'GTK_IS_LABEL (label)' failed

(gui.py:20607): Gtk-CRITICAL **: gtk_container_foreach: assertion 'GTK_IS_CONTAINER (container)' failed

关于对话框:

  <object class="GtkAboutDialog" id="StatsAbout">
    <property name="can_focus">False</property>
    <property name="title">...name of the program...</property>
    <property name="resizable">False</property>
    <property name="window_position">center-on-parent</property>
    <property name="icon_name">..icon...</property>
    <property name="type_hint">dialog</property>
    <property name="has_resize_grip">False</property>
    <property name="program_name">...name of a program...</property>
    <property name="version">1.0</property>
<property name="version">1.0</property>
    <property name="copyright">...my name...</property>
    <property name="comments" translatable="yes">...description...</property>
    <property name="website">...my website...</property>
    <property name="website_label" translatable="yes">...name of a website...</property>
    <property name="license">...very long license...</property>
<property name="authors">...authors...</property>
    <property name="artists">...artists...</property>
    <property name="logo_icon_name">...icon...</property>
    <property name="wrap_license">True</property>
    <property name="license_type">custom</property>
    <signal name="close" handler="about_destroy" swapped="no"/>
    <signal name="destroy" handler="about_destroy" swapped="no"/>
    <signal name="response" handler="about_destroy" swapped="no"/>
    <child internal-child="vbox">
      <object class="GtkBox" id="AboutContainer">
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <property name="spacing">2</property>
        <child internal-child="action_area">
          <object class="GtkButtonBox" id="AboutButtons">
            <property name="can_focus">False</property>
            <property name="layout_style">end</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="pack_type">end</property>
            <property name="position">0</property>
          </packing>
        </child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>

我自己解决了我的问题

我现在正在使用 .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()