gpt4 book ai didi

python - 如何多次显示用 Glade 定义的对话框?

转载 作者:行者123 更新时间:2023-12-01 08:57:26 32 4
gpt4 key购买 nike

我想多次显示在 Glade 文件中定义的 Gtk.Dialog

目前,我可以使用自定义按钮来调用对话框的 hide() 方法,但是,如果用户使用 Alt+F4 关闭对话框,它重新打开为空:

enter image description here

在控制台中我看到多个错误:

(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()获取对话框的实例:

 self.__settings_dialog : Gtk.Dialog = self.__builder.get_object("settings_dialog")

而不仅仅是调用 show()hide()。但是用 Alt+F4 关闭它后,我无法再次显示它。

最佳答案

感谢a Reddit user ,我发现您必须连接到对话框的 delete-event 并确保返回 True 以避免对话框被破坏。

首先在 Glade 中创建信号处理程序,然后在 Python 代码中创建:

def on_dialog_delete_event(self, dialog, event):
dialog.hide()
return True

关于python - 如何多次显示用 Glade 定义的对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52703513/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com