from kivy.app import App
from kivy.uix.scrollview import ScrollView
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.properties import BooleanProperty
from kivy.lang.builder import Builder
Builder.load_file('minimal.kv')
class Scroll(ScrollView):
pass
class Waypoints(GridLayout):
pass
class Root(FloatLayout):
pass
class Waypoint(RelativeLayout):
active = BooleanProperty()
class ServerApp(App):
def build(self):
super().build()
def add_waypoint(self):
wp = Waypoint()
label = Label(text="hey", font_size='40sp')
wp.add_widget(label)
self.waypoints.add_widget(wp)
def initialize_kivy(self):
self.wps = []
# Base layout
self.root = Root()
# Waypoints
self.scroll = Scroll()
self.root.add_widget(self.scroll)
self.waypoints = Waypoints()
self.scroll.add_widget(self.waypoints)
self.add_waypoint()
self.add_waypoint()
self.add_waypoint()
self.add_waypoint()
self.add_waypoint()
self.add_waypoint()
if __name__ == "__main__":
app = ServerApp()
app.initialize_kivy()
app.run()
<Scroll>:
pos_hint: {"right": 1, "top": 1}
size_hint: (1, 1)
canvas.before:
Color:
rgba: (0, 0, 0, 1)
Rectangle:
size: self.size
pos: self.pos
<Waypoints>:
cols: 1
size_hint: (1, None)
height: self.minimum_height
padding: 0, 0
spacing: 0, 0
canvas.before:
Color:
rgba: (1, 1, 1, .2)
Rectangle:
size: self.size
pos: self.pos
<Waypoint>:
size_hint: (1, None)
height: 50
canvas.before:
Color:
rgba: (0, 0, 0, .5) # if self.active else (1, .0, .0, .05)
Rectangle:
size: self.size
pos: self.pos
I don’t know the answer…
There is a discussion in the docs on RelativeLayouts and some common pitfalls: https://kivy.org/doc/stable/api-kivy.uix.relativelayout.html?highlight=relativelayout#module-kivy.uix.relativelayout
I don’t know if this is applicable…
--
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/4390565f-800e-4ec8-9de8-438ea99343d2%40googlegroups.com.
As all positions within a
RelativeLayout
are relative to the position of the layout itself, the position of the layout should never be used in determining the position of sub-widgets or the layout’scanvas
.
from kivy.app import App
from kivy.uix.label import Label
class ServerApp(App):
def build(self):
print('really build widgets')
return Label(text='blah')
if __name__ == "__main__":
app = ServerApp()
print('build widgets')
app.run()
There is something unusual about this App, I don't know if it is relevant. But it might generate unexpected behavior:The widget tree is built before the build call: