pygtk:如何从 popup_menu 切换 window_state

发布于 11-18 13:00 字数 1005 浏览 3 评论 0原文

这是我的代码:

def configure_event(self, widget):
    if self.is_hiding:
        self.window.present()
    else:
        self.window.iconify()

def delete_event(self, widget, data=None):
    gtk.main_quit()
    return True

def popup_menu(self):
    self.menu = gtk.Menu()
    self.about = gtk.MenuItem("about")
    if self.is_hiding:
        self.expand = gtk.MenuItem("show")
    else:
        self.expand = gtk.MenuItem("hide")

    self.quit = gtk.MenuItem("quit")

    self.about.connect("activate", self.about_monitor)
    self.expand.connect("activate", self.configure_event)
    self.quit.connect("activate", self.delete_event)

    self.menu.popup(None, None, gtk.status_icon_position_menu, event_button, event_time, self.tray_icon)

    self.menu.append(self.about)
    self.menu.append(self.expand)
    self.menu.append(self.monitor)
    self.menu.append(self.quit)

    self.menu.show_all()

delete_event 有效,但 configure_event 无效。为什么?

This is my code:

def configure_event(self, widget):
    if self.is_hiding:
        self.window.present()
    else:
        self.window.iconify()

def delete_event(self, widget, data=None):
    gtk.main_quit()
    return True

def popup_menu(self):
    self.menu = gtk.Menu()
    self.about = gtk.MenuItem("about")
    if self.is_hiding:
        self.expand = gtk.MenuItem("show")
    else:
        self.expand = gtk.MenuItem("hide")

    self.quit = gtk.MenuItem("quit")

    self.about.connect("activate", self.about_monitor)
    self.expand.connect("activate", self.configure_event)
    self.quit.connect("activate", self.delete_event)

    self.menu.popup(None, None, gtk.status_icon_position_menu, event_button, event_time, self.tray_icon)

    self.menu.append(self.about)
    self.menu.append(self.expand)
    self.menu.append(self.monitor)
    self.menu.append(self.quit)

    self.menu.show_all()

delete_event works, but configure_event does not. Why?

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

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

发布评论

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

评论(1

遮了一弯2024-11-25 13:00:01

查看它们两个的签名:

def configure_event(self, widget):
def delete_event(self, widget, data=None):

delete_event 有第三个参数 data(默认值为 None),但 configure_event< /code> 只有两个。

虽然我不知道例外是什么,但我打赌例外是:

TypeError: configure_event() takes exactly 2 arguments (3 given)

如果是这样,将 configure_event 的签名更改为:

def configure_event(self, widget, data):

会修复它。请注意,我认为 None 的默认值是不必要的,因为 gtk 总是会传递一些东西。

look at the signatures of both of them:

def configure_event(self, widget):
def delete_event(self, widget, data=None):

delete_event has a third argument data (that has a default of None) but configure_event only has two.

although i don't know what the exception was i bet that the exception was:

TypeError: configure_event() takes exactly 2 arguments (3 given)

if so changing configure_event's signature to:

def configure_event(self, widget, data):

would fix it. note that i think the default value of None is unneeded as gtk will pass something in always.

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