Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

kivy drawing

32 views
Skip to first unread message

Degenerate Tech

unread,
May 27, 2024, 9:25:42 AM5/27/24
to Kivy users support
in kv file drawing in canvas.before change with while changing window size by mouse
but while drawing with pyhton with state ment
drawing's position not change with window size change using mouse . how to solve ?

run this code and change window size by mouse see . the problem i am facing .
thmeter.kv
thmeter.py

Degenerate Tech

unread,
May 27, 2024, 10:48:53 AM5/27/24
to Kivy users support
i was doing some thing to update points but where i am wrong ?
self.bind(y= partial(self.update_y,obj,self.center_x),
                  center_x=partial(self.update_x,obj,i))
i+=10

def update_x(self,*args):
args[0].points=(args[-1]-self.line_gap+dp(3),args[1],args[-1]+self.line_gap-dp(9),args[1])

#args[0].
def update_y(self,*args):
args[0].points=(args[1]-self.line_gap+dp(3),args[1],args[-1]+self.line_gap-dp(9),args[1])

ELLIOT GARBUS

unread,
May 27, 2024, 1:42:33 PM5/27/24
to kivy-...@googlegroups.com
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()



From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of Degenerate Tech <sksah...@gmail.com>
Sent: Monday, May 27, 2024 6:25 AM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] kivy drawing
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c478cfd5-b498-4c22-b88a-38a5843bb2e5n%40googlegroups.com.

ElliotG

unread,
May 27, 2024, 8:45:44 PM5/27/24
to Kivy users support
I realized I could bind to center... this is a little cleaner that binding to the parent.


from kivy.properties import NumericProperty,ObjectProperty,ColorProperty,ListProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.metrics import dp
from kivy.utils import get_color_from_hex
from kivy.graphics import Color,Line,Rectangle
from kivy.lang import Builder
from kivy.clock import Clock

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel,MDIcon

from kivy_gradient import Gradient


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.bind(center=self.size_change)
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()


class MyApp(MDApp):
def build(self):
return Builder.load_file('./thmeter.kv')

if __name__=="__main__":
MyApp().run()


Reply all
Reply to author
Forward
0 new messages