Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.uix.floatlayout import FloatLayout
  4. from kivy.uix.boxlayout import BoxLayout
  5. from kivy.uix.button import Button
  6. from kivy.config import Config
  7. from kivy.core.window import Window
  8. import random
  9.  
  10. Builder.load_string("""
  11. <Boxes>:
  12. boxes: _boxes
  13. AnchorLayout:
  14. anchor_x: 'center'
  15. anchor_y: 'top'
  16. BoxLayout:
  17. orientation: 'horizontal'
  18. size_hint: 1, .1
  19. Button:
  20. text: 'Logo'
  21. on_press: _screen_manager.current = 'screen1'
  22. Button:
  23. text: 'Settings'
  24. on_press: _screen_manager.current = 'screen2'
  25.  
  26. AnchorLayout:
  27. anchor_x: 'center'
  28. anchor_y: 'center'
  29. ScreenManager:
  30. size_hint: 1, .7
  31. id: _screen_manager
  32. Screen:
  33. name: 'screen1'
  34. BoxLayout:
  35. orientation: 'vertical'
  36. padding: 50
  37. id: _boxes
  38. Screen:
  39. name: 'screen2'
  40. Label:
  41. text: 'Another Screen'
  42. AnchorLayout:
  43. anchor_x: 'center'
  44. anchor_y: 'bottom'
  45. ScreenManager:
  46. size_hint: 1, .1
  47. id: _screen_manager
  48. Screen:
  49. name: 'screen1'
  50. BoxLayout:
  51. orientation: 'vertical'
  52. padding: 10
  53. Button:
  54. text: 'Settings'
  55. on_press: _screen_manager.current = 'screen2'
  56. Screen:
  57. name: 'screen2'
  58. Label:
  59. text: ''""")
  60.  
  61. class Boxes(FloatLayout):
  62. def __init__(self, **kwargs):
  63. super(Boxes, self).__init__(**kwargs)
  64. bx1 = BoxLayout(orientation='horizontal')
  65. bx2 = BoxLayout(orientation='horizontal')
  66. bx3 = BoxLayout(orientation='horizontal')
  67. bx4 = BoxLayout(orientation='horizontal')
  68. bx5 = BoxLayout(orientation='horizontal')
  69. bx6 = BoxLayout(orientation='horizontal')
  70. bx7 = BoxLayout(orientation='horizontal')
  71. bx8 = BoxLayout(orientation='horizontal')
  72.  
  73. for i in range(1,9):
  74. bx1.add_widget(Button(text=str(i), on_press=buttonPress))
  75. for i in range(9,17):
  76. bx2.add_widget(Button(text=str(i), on_press=buttonPress))
  77. for i in range(17,25):
  78. bx3.add_widget(Button(text=str(i), on_press=buttonPress))
  79. for i in range(25,33):
  80. bx4.add_widget(Button(text=str(i), on_press=buttonPress))
  81. for i in range(33,41):
  82. bx5.add_widget(Button(text=str(i), on_press=buttonPress))
  83. for i in range(41,49):
  84. bx6.add_widget(Button(text=str(i), on_press=buttonPress))
  85. for i in range(49,57):
  86. bx7.add_widget(Button(text=str(i), on_press=buttonPress))
  87. for i in range(57,65):
  88. bx8.add_widget(Button(text=str(i), on_press=buttonPress))
  89.  
  90. self.boxes.add_widget(bx1)
  91. self.boxes.add_widget(bx2)
  92. self.boxes.add_widget(bx3)
  93. self.boxes.add_widget(bx4)
  94. self.boxes.add_widget(bx5)
  95. self.boxes.add_widget(bx6)
  96. self.boxes.add_widget(bx7)
  97. self.boxes.add_widget(bx8)
  98.  
  99. def buttonPress(obj):
  100. print('button pressed:', obj)
  101. # obj.background_normal = random.choice(["images/track/horizontal.png","images/track/cross.png"])
  102. obj.background_color= (random.uniform(0, 1), random.uniform(0, 1), random.uniform(0, 1), 1.0)
  103.  
  104. Config.set('graphics','resizable', False)
  105. Window.size = (600, 600)
  106. class TestApp(App):
  107. def build(self):
  108. return Boxes()
  109.  
  110. if __name__ == '__main__':
  111. TestApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement