SHARE
TWEET

Untitled

a guest Jul 16th, 2019 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from kivy.app import App
  2. from kivy.uix.boxlayout import BoxLayout
  3. from kivy.uix.button import Button
  4. from kivy.uix.label import Label
  5. from kivy.uix.screenmanager import ScreenManager, Screen
  6.  
  7. from functools import partial
  8.  
  9.  
  10. class Helper(Screen):
  11.     def __init__(self, prompt, options):
  12.         super().__init__()
  13.  
  14.         layout = BoxLayout(orientation='vertical')
  15.        
  16.         self.prompt = prompt
  17.         layout.add_widget(Label(text=prompt))
  18.  
  19.         choices = BoxLayout(orientation='horizontal')
  20.        
  21.         for option in options:
  22.             button = Button(text=option[0])
  23.             button.bind(on_press=partial(self.changeScreen, option[1]))
  24.             choices.add_widget(button)
  25.         layout.add_widget(choices)
  26.  
  27.         self.add_widget(layout)
  28.  
  29.     def changeScreen(self, location, touch):
  30.         self.parent.current = location
  31.  
  32. class Left(Helper):
  33.     def __init__(self):
  34.         self.name = 'left'
  35.        
  36.         prompt = "Up or Down?"
  37.  
  38.         super().__init__(prompt, [['Up', 'up'], ['Down', 'down']])
  39.  
  40.  
  41. class Right(Helper):
  42.     def __init__(self):
  43.         self.name = 'right'
  44.        
  45.         prompt = "You lose"
  46.  
  47.         super().__init__(prompt, [])
  48.  
  49.  
  50. class Start(Helper):
  51.     def __init__(self):
  52.         self.name = 'start'
  53.        
  54.         prompt = "Left or Right?"
  55.        
  56.         super().__init__(prompt, [['Left', 'left'], ['Right', 'right']])
  57.  
  58.  
  59. class AdventureApp(App):
  60.     def build(self):
  61.         sm = ScreenManager()
  62.         sm.add_widget(Start())
  63.         sm.add_widget(Left())
  64.         sm.add_widget(Right())
  65.  
  66.         return sm
  67.  
  68. AdventureApp().run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top