python - Drawing line at init method with widget relative coordinates -


I want to draw a line inside the widget but I have noticed that the relative position and the size of the widget are not set until the init method is over has been done.

How can I draw a graphic element inside a visual when I use my relative position and dimension? (I would like to save from KV lang)

  square track (define): def __init __ (self, ** kw): super (track, self) .__ init __ (** kw) .canvas with its own: color (1,0,0) line (number = (self. X, (itself .y + self.height) / 2, self. X + self, method (self .y + self. Height) / 2))  

In this way this initial size and position which is 100,100 and 0,0, but the widget has been drawn from within the layout, so I use relative I want to position and size and I want to draw it in init Are

I would like to recommend the removal of the ban.

In this way, the line has been prepared using the initial shape and position which is 100,100 and 0,0. But the widget is inside this one layout so I want to use relative position and size and I want to draw it in init.

You have three options: Is set in kivy.clock.clock ) which runs after the widget - it should be enough to do Clock.schedule_once (the_func, 0)) Together, the calculation is done after the 0 widget (assuming a normal layout), but the next Before ram The downside is that the line will be fixed again, and if it ever moves, the widget will not match, e.g. Probably during window resizing.

The second (and better) option is that you want to draw the line in the form of a line, but bind the widget and restore the function appropriately. There is a method with self.bind (pos = self.line_setter, size = self.line_setter) and self.line_setter self.line.points = [ . ..] as is appropriate for you self.line = Line (...) .

will need to save line references. The third (and usually the best) option is to use the KV language, which automatically binds you with any additional syntax.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -