'NumericProperty wont update
I am trying to update the position of a widget via a NumericProperty. I have it updated in a function. When the function has been called the NumericProperty wont update
main.py
class Game(Screen):
x = 0
y = 0
x_value = NumericProperty(x)
y_value = NumericProperty(y)
def update(self):
self.x = self.x + 20
self.y = self.y + 30
main.kv
Game:
FloatLayout:
Button:
text: "higher"
pos: (root.x_value + root.y_value)
on_release: root.update()
The Button stays at the same position. What can I do?
Solution 1:[1]
Your NumericProperty definitions are equivalent to x_value = NumericProperty(0), they don't know anything about the fact that the argument passed to them was named x in the local namespace. It looks like you expect updating self.x later will affect the NumericProperty, but this is not the case.
You can instead directly write self.x_value = self.x_value + 20 without reference to the initial-value variable. This should do what you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | inclement |
