如何根据Kivy中另一个小部件的值禁用小部件

时间:2017-07-20 03:12:23

标签: python python-2.7 kivy kivy-language

我在.kv文件中有一个Spinner小部件,我需要此Spinner的值来启用另一个Spinner小部件。

这是我尝试的代码,它不起作用,并给我一个语法错误:

CustLabel:
    text: "Aux LO Pump Status"


CustSpinner:
    id: auxlo
    text: "Select"
    values: ('On', 'Off')
    focus: True
    on_state: (self.auxlonum.disabled) if (self.auxlo == 'off')

CustLabel:
    text: "Aux LO Pump Number"

CustSpinner:
    id: auxlonum
    text: "Select"
    values: ('# 1', '# 2')
    focus: True

我实际上更喜欢使用auxlonum小部件来启动禁用和“灰色”'然后只有在auxlo小部件有'开启时才启用选择了,但我不知道该怎么做。

谢谢。

1 个答案:

答案 0 :(得分:2)

首先,您不能使用USE IMS_Location SELECT TOP(1000) (LOT_LOC_BOND.LOT_ID + LOT_LOC_IEBT.LOT_ID + LOT_LOC_MBT.LOT_ID + LOT_LOC_SEAL.LOT_ID) AS LOT_ID, LOT_LOC_BOND.LOT_ID, LOT_LOC_BOND.CheckIn AS BOND_CheckIn, LOT_LOC_BOND.CheckOut As BOND_CheckOut, LOT_LOC_BOND.StatusDesc AS BOND_Status, LOT_LOC_IEBT.LOT_ID, LOT_LOC_IEBT.CheckIn AS IEBT_CheckIn, LOT_LOC_IEBT.CheckOut AS IEBT_CheckOut, LOT_LOC_IEBT.StatusDesc AS IEBT_Status, LOT_LOC_MBT.LOT_ID, LOT_LOC_MBT.CheckIn AS MBT_CheckIn, LOT_LOC_MBT.CheckOut AS MBT_CheckOut, LOT_LOC_MBT.StatusDesc AS MBT_Status, LOT_LOC_SEAL.LOT_ID, LOT_LOC_SEAL.CheckIn AS SEAL_CheckIn, LOT_LOC_SEAL.CheckOut AS SEAL_CheckOut, LOT_LOC_SEAL.StatusDesc AS SEAL_Status FROM LOT_LOC_BOND LEFT JOIN LOT_LOC_IEBT ON LOT_LOC_BOND.LOT_ID = LOT_LOC_IEBT.LOT_ID, LOT_LOC_MBT LEFT JOIN LOT_LOC_SEAL ON LOT_LOC_MBT.LOT_ID = LOT_LOC_SEAL.LOT_ID ORDER BY LOT_ID 事件,因为它在您选择一个值之前发出。您需要使用on_state事件。

另一方面,on_text语法不正确,您应该仅使用self.auxlonum来引用kv中的任何小部件。

最后,您只需要使用三元运算符语法来执行您想要的操作:

id

或者:

Spinner:
    id: auxlo
    on_text: auxlonum.disabled = True if auxlo.text == 'Off' else False

可执行示例:

Spinner:
    id: auxlonum
    disabled: True if auxlo.text == 'Off' else False

enter image description here