Skip to content

Instantly share code, notes, and snippets.

@tito
Forked from MightyThor/switchingwidgets.kv
Last active December 13, 2015 20:58
Show Gist options
  • Save tito/4973413 to your computer and use it in GitHub Desktop.
Save tito/4973413 to your computer and use it in GitHub Desktop.
#: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')
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