Advertisement
Guest User

Cartouche

a guest
Aug 18th, 2015
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.90 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.screenmanager import ScreenManager, Screen
  4.  
  5. # Create both screens. Please note the root.manager.current: this is how
  6. # you can control the ScreenManager from kv. Each screen has by default a
  7. # property manager that gives you the instance of the ScreenManager used.
  8. Builder.load_string("""
  9. <MenuScreen>:
  10.    BoxLayout:
  11.        Button:
  12.            text: 'Commande'
  13.            on_press: root.manager.current = 'commande'
  14.        Button:
  15.            text: 'Nouveau Produit'
  16.            on_press: root.manager.current = 'produit'
  17.        Button:
  18.            text: 'Statistiques'
  19.            on_press: root.manager.current = 'stats'
  20.        Button:
  21.            text: 'Goto settings'
  22.            on_press: root.manager.current = 'settings'
  23.        Button:
  24.            text: 'Quit'
  25. <ProduitScreen>:
  26.    GridLayout:
  27.        rows: 3
  28.        cols: 2
  29.        padding: 10
  30.        spacing: 10
  31.        Label:
  32.            font_size: 20
  33.            text: 'Nom du produit'
  34.        TextInput:
  35.            font_size: 20
  36.            id: nom
  37.        Label:
  38.            font_size: 20
  39.            text: 'Prix'
  40.        TextInput:
  41.            font_size: 20
  42.            id: prix
  43.        Button:
  44.            text: 'Ajouter'
  45.            on_press: self.ajouter()
  46.        Button:
  47.            text: 'Quitter'
  48.            on_press: root.manager.current = 'menu'
  49.  
  50. <CommandeScreen>:
  51.    GridLayout:
  52.        rows: 4
  53.        cols: 2
  54.        Label:
  55.            text: 'Prix : '
  56.        Label:
  57.            text: '0.00 Euros'
  58.        Button:
  59.            text: 'Coca'
  60.        Label:
  61.            text: '1.80 euros'
  62.        Button:
  63.            text: 'Orangina'
  64.        Label:
  65.            text: '1.80 euros'
  66.        Button:
  67.            text: 'Ajouter'
  68.        Button:
  69.            text: 'Quitter'
  70.            on_press: root.manager.current = 'menu'
  71.  
  72. <StatsScreen>:
  73.    Button:
  74.        text: 'Quitter'
  75.        on_press: root.manager.current = 'menu'
  76.  
  77. <SettingsScreen>:
  78.    BoxLayout:
  79.        Button:
  80.            text: 'My settings button'
  81.        Button:
  82.            text: 'Back to menu'
  83.            on_press: root.manager.current = 'menu'
  84. """)
  85.  
  86. # Declare both screens
  87. class MenuScreen(Screen):
  88.     pass
  89.  
  90. class ProduitScreen(Screen):
  91.     def ajouter():
  92.         print "%s au prix de %d a ete ajoute" % (self.nom.txt , float(self.prix.txt))
  93.  
  94. class CommandeScreen(Screen):
  95.     pass
  96.  
  97. class StatsScreen(Screen):
  98.     pass
  99.  
  100. class SettingsScreen(Screen):
  101.     pass
  102.  
  103. # Create the screen manager
  104. sm = ScreenManager()
  105. sm.add_widget(MenuScreen(name='menu'))
  106. sm.add_widget(SettingsScreen(name='settings'))
  107. sm.add_widget(ProduitScreen(name='produit'))
  108. sm.add_widget(CommandeScreen(name='commande'))
  109. sm.add_widget(StatsScreen(name='stats'))
  110.  
  111. class TestApp(App):
  112.  
  113.     def build(self):
  114.         return sm
  115.  
  116. if __name__ == '__main__':
  117.     TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement