我想多次显示Glade文件中定义的Gtk.Dialog
。
当前,我可以使用自定义按钮来调用Dialog的hide()
方法,但是,如果用户使用 Alt + F4 关闭对话框,它重新打开为空:
在控制台中,我看到多个错误:
(main.py:29152): Gtk-CRITICAL **: 15:28:29.637: gtk_container_foreach: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_button_box_get_layout: assertion 'GTK_IS_BUTTON_BOX (widget)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.651: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_button_box_get_layout: assertion 'GTK_IS_BUTTON_BOX (widget)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:29.697: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_box_get_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_box_set_spacing_set: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_button_box_get_layout: assertion 'GTK_IS_BUTTON_BOX (widget)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_box_set_spacing: assertion 'GTK_IS_BOX (box)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_get_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: gtk_container_set_border_width: assertion 'GTK_IS_CONTAINER (container)' failed
(main.py:29152): Gtk-CRITICAL **: 15:28:31.141: _gtk_container_set_border_width_set: assertion 'GTK_IS_CONTAINER (container)' failed
我正在使用普通的get_object()
获取Dialog的实例:
self.__settings_dialog : Gtk.Dialog = self.__builder.get_object("settings_dialog")
,而不仅仅是调用show()
和hide()
。但是用 Alt + F4 将其关闭后,我将无法再次显示它。
答案 0 :(得分:1)
感谢a Reddit user,我发现您必须连接到对话框的delete-event
,并确保返回True
以避免对话框被破坏。
首先在Glade中创建信号处理程序,然后在您的Python代码中创建
:def on_dialog_delete_event(self, dialog, event):
dialog.hide()
return True