Advertisement
obernardovieira

Inheritance with Kivy

Oct 14th, 2016
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. ## This is the controller.kv file
  2.  
  3. #:kivy 1.0
  4.  
  5. <MyContainer>:
  6.     Button:
  7.         text: 'My controller info is: '
  8.  
  9. <Controller>:
  10.  
  11.  
  12. ## And this is the main.py file
  13.  
  14. import kivy
  15. kivy.require('1.0.5')
  16.  
  17. from kivy.uix.floatlayout import FloatLayout
  18. from kivy.uix.boxlayout import BoxLayout
  19. from kivy.app import App
  20.  
  21. class MyContainer(BoxLayout):
  22.  
  23.     def do_action(self):
  24.         print "hi!"
  25.  
  26. class Controller(MyContainer):
  27.     def __init__(self, **kwargs):
  28.         self.do_action()
  29.         super(Controller, self).__init__(**kwargs)
  30.  
  31. class ControllerApp(App):
  32.  
  33.     def build(self):
  34.         return Controller()
  35.  
  36. if __name__ == '__main__':
  37.     ControllerApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement