我知道“切换或未切换”事件不存在,但我需要使用这样的事件。当按钮处于“切换”和“未切换”状态时,是否存在要执行任务的事件。我不想使用“clicked”事件,因为ToggleButton可以在没有单击的情况下被切换或不被切换
谢谢
示例
def foo(obj):
if obj.get_active():
print("toggled")
else:
print("untoggled")
mybtn = gtk.ToggleButton()
mybtn.connect("toggled-or-untoggled", foo)
Tags:
下面是一个简短的GTK2+/PyGTK演示;如果需要,它应该很容易适应GTK3。在
GUI包含一个切换按钮和一个普通按钮。ToggleButton的回调函数只打印按钮的状态,无论是通过用户单击它还是通过其他代码调用它的
set_active
方法。普通按钮在单击时打印一条消息,它还可以切换ToggleButton。在典型输出
^{pr2}$根据the docs-
因此,理想情况下,
mybtn.connect("toggled", foo)
应该可以工作。在相关问题 更多 >
编程相关推荐