如何从不敏感的小部件获取点击和其他信号?
How to get click and another signals from insensitive widget?
我想从不敏感的小部件获取信号。但是当小部件对 widget.set_sensitive(False)
代码行不敏感时,这个小部件的信号不起作用。我怎样才能确保不敏感的小部件的信号正常工作?
例子
w = Gtk.Button("example")
w.set_sensitive(False)
w.connect("button-press-event", do_anything) # not work
我只想冻结小部件。但是小部件完全不能以这种方式工作。
这就是微件不敏感的意思。如果是这样,它们将不会向事件发出信号,您将无法与它们交互。
在某些情况下,您希望小部件不敏感,例如,假设身份验证对话框中有一个 "Login" 按钮,但您只想在用户名和密码都不为空时允许登录。然后您可以检查条目内容,如果 none 为空,则将 "Login" 设置为敏感。
来自 Python API - Gtk.Widget set_sensitive 方法:
Sets the sensitivity of a widget. A widget is sensitive if the user
can interact with it. Insensitive widgets are “grayed out” and the
user can’t interact with them. Insensitive widgets are known as
“inactive”, “disabled”, or “ghosted” in some other toolkits.
您必须将按钮打包到 EventBox 中。
e_b = Gtk.Eventbox()
button = Gtk.Button()
e_b.add(button)
e_b.set_above_child(True) #necessary for event handling
e_b.connect("button-press-event", do_anything)
但是,这让我想知道你想做什么。请参阅@JoseFonte 的回答。
我想从不敏感的小部件获取信号。但是当小部件对 widget.set_sensitive(False)
代码行不敏感时,这个小部件的信号不起作用。我怎样才能确保不敏感的小部件的信号正常工作?
例子
w = Gtk.Button("example")
w.set_sensitive(False)
w.connect("button-press-event", do_anything) # not work
我只想冻结小部件。但是小部件完全不能以这种方式工作。
这就是微件不敏感的意思。如果是这样,它们将不会向事件发出信号,您将无法与它们交互。
在某些情况下,您希望小部件不敏感,例如,假设身份验证对话框中有一个 "Login" 按钮,但您只想在用户名和密码都不为空时允许登录。然后您可以检查条目内容,如果 none 为空,则将 "Login" 设置为敏感。
来自 Python API - Gtk.Widget set_sensitive 方法:
Sets the sensitivity of a widget. A widget is sensitive if the user can interact with it. Insensitive widgets are “grayed out” and the user can’t interact with them. Insensitive widgets are known as “inactive”, “disabled”, or “ghosted” in some other toolkits.
您必须将按钮打包到 EventBox 中。
e_b = Gtk.Eventbox()
button = Gtk.Button()
e_b.add(button)
e_b.set_above_child(True) #necessary for event handling
e_b.connect("button-press-event", do_anything)
但是,这让我想知道你想做什么。请参阅@JoseFonte 的回答。