如何禁用 Kivy 中的小部件?

2022-01-15 00:00:00 python kivy user-interface widget

问题描述

我阅读了 Kivy 教程,但找不到如何禁用小部件(例如,按钮).

I read the Kivy tutorial and couldn't find how to disable a widget (for example, a Button).

def foo(self, instance, *args):
  #... main business logic, and then
  instance.disable = False
  # type(instance) = kivy.uix.Button

我将 foofunctools.partial 绑定.

什么是正确的参数?


解决方案

如果你使用的是 kivy 版本 >= 1.8 那么你可以做 widget.disabled = True.如果在以前的版本中您可以简单地自行管理禁用,只需确保它不会对触摸做出反应并在禁用时显示另一种外观.

If you are using kivy version >= 1.8 then you can just do widget.disabled = True. If on previous versions you can simply manage the disabling yourself, just make sure it doesn't react to touch and displays a alternative look when disabled.

相关文章