Reputation: 176
I'm making a game in kivy and when I close the screen (android) or try to resize the window (linux) some widgets that I've moved away from the screen return to their starting position. I created a minimal reproducible example for that:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class GameCanvas(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def start(self):
# move the label widget far away
self.children[0].pos = 10000, 10000
class Example(App):
pass
if __name__ == '__main__':
Example().run()
GameCanvas:
<GameCanvas>:
Button:
text: 'Start Game'
size: root.width, root.height / 2
on_release: root.start()
Label:
text: 'Game Title'
size: root.width, root.height / 2
As the attached images show after I press the button the label 'disappears' (moves position) but when I try to resize the Window it comes back.
Why does this happen? Also why does it happen on android as well? Does it have to do with some sort of events in kivy?
Thanks in advance!
Upvotes: 0
Views: 265
Reputation: 38962
The behavior you see is the intended behavior of the BoxLayout
. The BoxLayout
positions its children. So, you can move the Label
, but as soon as the BoxLayout
gets a chance (as in a size change event), it positions its children as intended. If you want to control the position of the children widgets, then you should use a Layout
that does not position its children, perhaps a FloatLayout
or RelativeLayout
Upvotes: 1