【发布时间】:2020-12-02 17:53:55
【问题描述】:
所以我不确定为什么我的一种方法不会覆盖当前的 on_press 绑定。我尝试使用 .unbind 方法,但也没有用。我尝试使用 lambda 并且只有在我只更改一个按钮时才真正起作用。我想创建一个图表,单击元组后,我可以使用“+”按钮更改数字。当我单击另一个元组时,我可以使用相同的“+”按钮更改该元组。使用 lambda 同时改变了它们两个
def PlusOne(buttonValue):
Result = float(buttonValue.text) + 1
buttonValue.text = str(Result)
print(str(buttonValue.text))
def ButtonPlusOne(button):
global x
if x == 1:
self.plusButton.unbind(on_press=PlusOne(button))
self.plusButton.bind(on_press=PlusOne(button))
print(str(button.text))
else:
self.plusButton.bind(on_press=PlusOne(button))
print(str("ElsePrint " + button.text))
x = 1
self.Button1.bind(on_press=ButtonPlusOne(self.Button1))
self.Button2.bind(on_press=ButtonPlusOne(self, self.Button2))
这将返回 AssertionError: None is not callable
【问题讨论】:
-
尝试调试它并查看'plusButton'在那个时间点的状态。它是您期望的对象吗?此代码中从未分配 self.plusButton。
-
on_press是指分配给一个函数,而不是调用一个函数的结果。