I am using the Kivy python library.
I have two widgets defined.
When the program runs, I run the first widget.
When that widgets button is pressed, I want it to dissapear and be replaced with the second widget.
Here is the .kv for the two widgets
#uitest.kv
<TestForm>:
canvas:
Rectangle:
pos: self.center_x, 0
size: 10, self.height
BoxLayout:
size: root.size
padding: 40
Button:
text: 'Hello'
on_release: root.testCallback()
<TestForm2>:
canvas:
Rectangle:
pos: self.center_x, 0
size: self.height, 10
My main python file runs the app, and returns the first widget
#main.py
from testform import TestForm
from kivy.app import App
class UITestApp(App):
def build(self):
return TestForm()
# Main launching point
if __name__ in ('__main__', '__android__'):
UITestApp().run()
My first widget has a callback. This is where the code-in-question belongs
from testform2 import TestForm2
from kivy.uix.widget import Widget
class TestForm(Widget):
def testCallback(self):
TestForm2() # Code in question goes here. @TODO replace this widget with TestForm2 widget.
The idea here is to have a user interface manager. This manager doesn't run the UI like a tree, but like a list and stack. The list holds instances of all my UI Forms. The stack holds the traversal of said forms, whenever we jump to a form we push it to the stack and "render" or whatever that one.
EDIT: I chose my answer, but in my searches I also found the Screen object: http://kivy.org/docs/api-kivy.uix.screenmanager.html Personally, the clear() and add() commands are more powerful, but the screen takes a lot of that out of your hands if you're interested. Transition effects too.