Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Well, you can find a complete explanation at my wordpress page
- # http://obernardovieira.byethost18.com/kivy-para-ti-python-gui-framework/
- # it's in portuguese, but translators are available
- # and also check my POS (point of sale) project with kivy, on github (in english)
- # https://github.com/obernardovieira/POS-System
- # Thank you so much ;)
- ## USE .KV FILE TO BUILD A GUI
- # test.py
- from kivy.app import App
- class TestApp(App):
- def build(self):
- pass
- TestApp().run()
- # test.kv
- #:kivy 1.0
- BoxLayout:
- Button:
- text: 'Hello 1!'
- BoxLayout:
- orientation: 'vertical'
- Button:
- text: 'Hello 2!'
- Button:
- text: 'Hello 3!'
- ## USE ONLY PYTHON
- # test.py
- from kivy.app import App
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.button import Button
- class TestApp(App):
- def build(self):
- mainWindow = BoxLayout()
- mainWindow.add_widget(Button(text='Hello 1!'))
- subWindow = BoxLayout(orientation='vertical')
- subWindow.add_widget(Button(text='Hello 2!'))
- subWindow.add_widget(Button(text='Hello 3!'))
- mainWindow.add_widget(subWindow)
- return mainWindow
- TestApp().run()
- ### USER .KV FILE AND FINISH WITH PYTHON CODE (DYNAMIC WAY)
- # test.py
- from kivy.app import App
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.button import Button
- from kivy.properties import ObjectProperty
- class Controller(BoxLayout):
- subBox = ObjectProperty()
- def __init__(self, **kwargs):
- super(Controller, self).__init__(**kwargs)
- self.subBox.add_widget(Button(text='Hello 2!'))
- self.subBox.add_widget(Button(text='Hello 3!'))
- class TestApp(App):
- def build(self):
- return Controller()
- TestApp().run()
- # test.kv
- #:kivy 1.0
- <Controller>:
- subBox: id_subBox
- BoxLayout:
- Button:
- text: 'Hello 1!'
- BoxLayout:
- orientation: 'vertical'
- id: id_subBox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement