Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.button import Button
- from kivy.uix.label import Label
- from kivy.uix.screenmanager import ScreenManager, Screen
- from functools import partial
- class Helper(Screen):
- def __init__(self, prompt, options):
- super().__init__()
- layout = BoxLayout(orientation='vertical')
- self.prompt = prompt
- layout.add_widget(Label(text=prompt))
- choices = BoxLayout(orientation='horizontal')
- for option in options:
- button = Button(text=option[0])
- button.bind(on_press=partial(self.changeScreen, option[1]))
- choices.add_widget(button)
- layout.add_widget(choices)
- self.add_widget(layout)
- def changeScreen(self, location, touch):
- self.parent.current = location
- class Left(Helper):
- def __init__(self):
- self.name = 'left'
- prompt = "Up or Down?"
- super().__init__(prompt, [['Up', 'up'], ['Down', 'down']])
- class Right(Helper):
- def __init__(self):
- self.name = 'right'
- prompt = "You lose"
- super().__init__(prompt, [])
- class Start(Helper):
- def __init__(self):
- self.name = 'start'
- prompt = "Left or Right?"
- super().__init__(prompt, [['Left', 'left'], ['Right', 'right']])
- class AdventureApp(App):
- def build(self):
- sm = ScreenManager()
- sm.add_widget(Start())
- sm.add_widget(Left())
- sm.add_widget(Right())
- return sm
- AdventureApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement