Widget.hide() 的问题

发布于 2024-09-16 01:25:42 字数 465 浏览 7 评论 0原文

问题:小部件“A”是在主窗口“B”中单击按钮后显示的顶级窗口。如何分配一个处理程序来处理单击小部件“A”窗口边框上的“X”后发回的信号(请参阅下面的当前实现)?

def on_mainWindow_B_button_clicked(self, widget):
     self.widget_a.show()

def on_widget_a_destroy(self, widget): #this is the handler I have right now yet after it's called and widget.a closes and 'on_mainWindow_B_button_clicked' is called for the second time none of widget.a's children appear in the new window
     widget.hide()

Problem: Widget 'A' is a toplevel window that is displayed after a button click in MainWindow 'B'. How do I assign a handler to handle the signal sent back after the 'X' along the window border of Widget 'A' is clicked (see below for current implementation)?

def on_mainWindow_B_button_clicked(self, widget):
     self.widget_a.show()

def on_widget_a_destroy(self, widget): #this is the handler I have right now yet after it's called and widget.a closes and 'on_mainWindow_B_button_clicked' is called for the second time none of widget.a's children appear in the new window
     widget.hide()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕头说它不想醒 2024-09-23 01:25:42

delete_event 信号的处理程序必须返回 True 才能阻止窗口在关闭时被永久销毁。

    self.widget_a.connect('delete_event', self.on_widget_a_delete)

def on_widget_a_delete(self, widget, event):
    widget.hide()
    # do something
    return True

如果您只想隐藏窗口,可以使用内置快捷方式:

self.widget_a.connect('delete_event', self.widget_a.hide_on_delete)

The handler for the delete_event signal must return True in order to stop the Window being permanently destroyed on closing.

    self.widget_a.connect('delete_event', self.on_widget_a_delete)

def on_widget_a_delete(self, widget, event):
    widget.hide()
    # do something
    return True

If you only want to have the window hide, there's a builtin shortcut you can use:

self.widget_a.connect('delete_event', self.widget_a.hide_on_delete)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文