I am new to Kivy GUI and I have a few questions related to kvlang:
1. How can I add my own widget class to root in the kv file? (example) PS: I use clear_widgets() , then I try to add my custom widget, but I get an error after clicking the button.
#:kivy 1.8 < HelloWorldForm@BoxLayout >: orientation: "vertical" Label: text:"Hello world" Button: text: "Go back" on_press: app.formGoBack() < MainForm@BoxLayout >: orientation: "vertical" btnOpenForm: btnChangeForm BoxLayout: size_hint_y:None height:"40dp" Button: id:btnChangeForm text:"Go to hello world form" on_press: root.clear_widgets() root.add_widget(HelloWorldForm) Button: id:btnExit text:"Exit" on_press: app.Exit() MainForm:
How to add a HelloWorldForm class to a widget class using the add_widget method
2. How can I use add_widget and clear_widgets in python code? (eg)
main.kv
< MainForm@BoxLayout >: orientation: "vertical" btnOpenForm: btnChangeForm BoxLayout: size_hint_y:None height:"40dp" Button: id:btnChangeForm text:"Go to hello world form" on_press: app.changeForm()
main.py
#!/usr/bin/python3.4 import kivy kivy.require('1.8.0') from kivy.app import App from kivy.uix import * class MainApp(App): def changeForm(self) /** TO-DO **/ app=MainApp() app.run()
3. How can I access kvlang properties in python? For example, I want to take text from a button. How can i achieve this?
source share