简体   繁体   English

如何用 PyGTK 连接“显示”和“隐藏”信号?

[英]How to connect the “show” and “hide” signals with PyGTK?

I would like to have a callback called when some widget (a Menu ) is shown or hidden.我希望在显示或隐藏某些小部件( Menu )时调用回调。 Doing this way:这样做:

menu = gtk.Menu()
menu.connect("show", self.menu_show, menu)
menu.connect("hide", self.menu_hide, menu)

Callback functions are never called.回调函数永远不会被调用。 Are show and hide signals the ones I am looking for? showhide信号是我正在寻找的信号吗? Are they special?它们很特别吗? Is there something I am missing to have this working?有什么我想念的东西吗?

I think those signals are emitted only when the respective methods on an object are called.我认为只有在调用 object 上的相应方法时才会发出这些信号。 If you want to connect to when a widget is (re-) drawn, take the expose-event signal.如果您想在(重新)绘制小部件时连接,请使用 expose-event 信号。 But why do you want to anyway?但是你为什么要这样做呢? A menu is there to provide to the user choices for actions, not to run some setup/teardown code when it is shown/hidden.有一个菜单向用户提供操作选择,而不是在显示/隐藏时运行某些设置/拆卸代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM