python - Kivy Adding Widget to a screen -
this seems silly question. have widget want add screen called gamescreen.
this python code:
class welcomescreen(screen): pass class basicscreen(screen): pass class gamescreen(screen): parent = widget() game = shootinggame() parent.add_widget(game) clock.schedule_interval(game.update, 1.0 / 60.0) # return parent sm = screenmanager() sm.add_widget(welcomescreen(name='welcome')) sm.add_widget(basicscreen(name='basic')) sm.add_widget(gamescreen(name='game')) class shootingapp(app): def build(self): print(sm.current) return sm if __name__ == '__main__': shootingapp().run()
and kivy code:
<welcomescreen>: button: text: "learn haptic illusions" size_hint: none, none size: 500, 70 pos: 100, 200 font_size: 30 on_release: app.root.current = "basic" button: text: "play our game" size_hint: none, none size: 500, 70 pos: 100, 100 font_size: 30 on_release: app.root.current = "game" <basicscreen>: name: "basic" <gamescreen>: name: "game"
the error getting this. , think because defined parent widget game. however, need parent because game widget uses width , height values of parent (e.g., self.parent.width). there workaround game widget can nested in parent , add parent screen?
kivy.uix.widget.widgetexception: cannot add <screen name='game'>, has parent <kivy.uix.widget.widget object @ 0x1093dc8d8>
thanks guys!!
you can this
class gamesscreen(screen): def __init__(self, **kwargs): super(gamescreen, self).__init__(**kwargs) self.game = shootinggame() self.add_widget(self.game) clock.schedule_interval(self.game.update, 1.0 / 60.0)
Comments
Post a Comment