Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.floatlayout import FloatLayout
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.button import Button
- from kivy.config import Config
- from kivy.core.window import Window
- import random
- Builder.load_string("""
- <Boxes>:
- boxes: _boxes
- AnchorLayout:
- anchor_x: 'center'
- anchor_y: 'top'
- BoxLayout:
- orientation: 'horizontal'
- size_hint: 1, .1
- Button:
- text: 'Logo'
- on_press: _screen_manager.current = 'screen1'
- Button:
- text: 'Settings'
- on_press: _screen_manager.current = 'screen2'
- AnchorLayout:
- anchor_x: 'center'
- anchor_y: 'center'
- ScreenManager:
- size_hint: 1, .7
- id: _screen_manager
- Screen:
- name: 'screen1'
- BoxLayout:
- orientation: 'vertical'
- padding: 50
- id: _boxes
- Screen:
- name: 'screen2'
- Label:
- text: 'Another Screen'
- AnchorLayout:
- anchor_x: 'center'
- anchor_y: 'bottom'
- ScreenManager:
- size_hint: 1, .1
- id: _screen_manager
- Screen:
- name: 'screen1'
- BoxLayout:
- orientation: 'vertical'
- padding: 10
- Button:
- text: 'Settings'
- on_press: _screen_manager.current = 'screen2'
- Screen:
- name: 'screen2'
- Label:
- text: ''""")
- class Boxes(FloatLayout):
- def __init__(self, **kwargs):
- super(Boxes, self).__init__(**kwargs)
- bx1 = BoxLayout(orientation='horizontal')
- bx2 = BoxLayout(orientation='horizontal')
- bx3 = BoxLayout(orientation='horizontal')
- bx4 = BoxLayout(orientation='horizontal')
- bx5 = BoxLayout(orientation='horizontal')
- bx6 = BoxLayout(orientation='horizontal')
- bx7 = BoxLayout(orientation='horizontal')
- bx8 = BoxLayout(orientation='horizontal')
- for i in range(1,9):
- bx1.add_widget(Button(text=str(i), on_press=buttonPress))
- for i in range(9,17):
- bx2.add_widget(Button(text=str(i), on_press=buttonPress))
- for i in range(17,25):
- bx3.add_widget(Button(text=str(i), on_press=buttonPress))
- for i in range(25,33):
- bx4.add_widget(Button(text=str(i), on_press=buttonPress))
- for i in range(33,41):
- bx5.add_widget(Button(text=str(i), on_press=buttonPress))
- for i in range(41,49):
- bx6.add_widget(Button(text=str(i), on_press=buttonPress))
- for i in range(49,57):
- bx7.add_widget(Button(text=str(i), on_press=buttonPress))
- for i in range(57,65):
- bx8.add_widget(Button(text=str(i), on_press=buttonPress))
- self.boxes.add_widget(bx1)
- self.boxes.add_widget(bx2)
- self.boxes.add_widget(bx3)
- self.boxes.add_widget(bx4)
- self.boxes.add_widget(bx5)
- self.boxes.add_widget(bx6)
- self.boxes.add_widget(bx7)
- self.boxes.add_widget(bx8)
- def buttonPress(obj):
- print('button pressed:', obj)
- # obj.background_normal = random.choice(["images/track/horizontal.png","images/track/cross.png"])
- obj.background_color= (random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), 1.0)
- Config.set('graphics','resizable', False)
- Window.size = (600, 600)
- class TestApp(App):
- def build(self):
- return Boxes()
- if __name__ == '__main__':
- TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement