You need to bind to a layout (or Window) that sees the size change. I used the parent of the ThermoMeter.
Bind to the size change, and redraw when the size changes.
class ThermoMeter(FloatLayout):
value=NumericProperty(0.52)
line_color=ColorProperty('brown')
line_width=NumericProperty(dp(1.2))
line_height=NumericProperty(dp(100))
line_gap=NumericProperty(dp(10))
background_color=ColorProperty('white')
label1_text_color=ColorProperty('gray')
ball_size=ListProperty([dp(25),dp(25)])
def on_kv_post(self,*args):
Clock.schedule_once(self._call)
self.parent.bind(size=self.size_change) # or could bind to window size
print(self.center_x)
def _call(self, *args):
print(self.center_x)
with self.canvas:
i=self.y+self.ball_size[1]
while i <(self.y+self.line_height):
Color(rgba=[0,0,1,1])
Line(points=(self.center_x-self.line_gap+dp(3),i, self.center_x+self.line_gap-dp(9),i))
i+=10
def size_change(self, obj, v):
print(f'size change: {v}')
self.canvas.clear()
self._call()