-
-
Save tito/4973413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:kivy 1.5.1 | |
#:import kivy kivy | |
<FirstWidget> | |
GridLayout: | |
size: root.size | |
rows: 2 | |
Label: | |
text: 'First Widget' | |
Button: | |
text: 'Go to Second' | |
on_press: app.root.widget_switcher('second') | |
<SecondWidget> | |
GridLayout: | |
size: root.size | |
rows: 2 | |
Label: | |
text: 'Second Widget' | |
Button: | |
text: 'Go to First | |
on_press: app.root.widget_switcher('first') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.uix.floatlayout import FloatLayout | |
class FirstWidget(Widget): | |
pass | |
class SecondWidget(Widget): | |
pass | |
class SwitchingWidgets(App): | |
def build(self): | |
parent = FloatLayout() | |
self.first = FirstWidget() | |
self.second = SecondWidget() | |
parent.add_widget(self.first) | |
return parent | |
def widget_switcher(self, string): | |
self.root.clear_widgets() | |
if string == 'first': | |
self.root.add_widget(self.first) | |
elif string == 'second': | |
self.root.add_widget(self.second) | |
if __name__ == '__main__': | |
SwitchingWidgets().run( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment