2012-03-19 14:51:29 +00:00
|
|
|
'''
|
|
|
|
TabbedPanel
|
|
|
|
============
|
|
|
|
|
|
|
|
Test of the widget TabbedPanel.
|
|
|
|
'''
|
|
|
|
|
|
|
|
from kivy.app import App
|
2012-04-06 21:52:34 +00:00
|
|
|
from kivy.uix.tabbedpanel import TabbedPanel
|
2012-03-19 14:51:29 +00:00
|
|
|
from kivy.lang import Builder
|
|
|
|
|
|
|
|
Builder.load_string("""
|
2012-04-06 21:52:34 +00:00
|
|
|
<Test>:
|
2012-03-19 14:51:29 +00:00
|
|
|
size_hint: .5, .5
|
2012-04-06 21:52:34 +00:00
|
|
|
pos_hint: {'center_x': .5, 'center_y': .5}
|
2012-03-19 14:51:29 +00:00
|
|
|
default_content: set1_content
|
2012-04-06 21:52:34 +00:00
|
|
|
|
2012-03-19 14:51:29 +00:00
|
|
|
Label:
|
|
|
|
id: set1_content
|
2012-04-06 21:52:34 +00:00
|
|
|
text: 'First tab content area'
|
|
|
|
|
2012-03-19 14:51:29 +00:00
|
|
|
BoxLayout:
|
|
|
|
id: set2_content
|
|
|
|
Label:
|
2012-04-06 21:52:34 +00:00
|
|
|
text: 'Second tab content area'
|
2012-03-19 14:51:29 +00:00
|
|
|
Button:
|
2012-04-06 21:52:34 +00:00
|
|
|
text: 'Button that does nothing'
|
|
|
|
|
|
|
|
RstDocument:
|
2012-03-19 14:51:29 +00:00
|
|
|
id: set3_content
|
2012-04-06 21:52:34 +00:00
|
|
|
text: '\\n'.join(("Hello world", "-----------", "You are in the third tab."))
|
|
|
|
|
|
|
|
# now categorize widgets inserted above in a specific header
|
2012-03-19 14:51:29 +00:00
|
|
|
TabbedPanelHeader:
|
2012-04-06 21:52:34 +00:00
|
|
|
text: 'Tab 2'
|
2012-04-06 22:15:52 +00:00
|
|
|
content: set2_content
|
2012-03-19 14:51:29 +00:00
|
|
|
TabbedPanelHeader:
|
2012-04-06 21:52:34 +00:00
|
|
|
text: 'Tab 3'
|
2012-04-06 22:15:52 +00:00
|
|
|
content: set3_content
|
2012-03-19 14:51:29 +00:00
|
|
|
""")
|
|
|
|
|
|
|
|
class Test(TabbedPanel):
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(Test, self).__init__(**kwargs)
|
|
|
|
self.change_tab_contents(self.default_content)
|
|
|
|
|
2012-04-06 22:02:12 +00:00
|
|
|
def on_default_tab(self, *l):
|
2012-03-19 14:51:29 +00:00
|
|
|
self.change_tab_contents(self.default_content)
|
|
|
|
|
|
|
|
def change_tab_contents(self, content, *l):
|
|
|
|
self.clear_widgets()
|
|
|
|
self.add_widget(content)
|
|
|
|
|
|
|
|
class MyApp(App):
|
|
|
|
def build(self):
|
|
|
|
return Test()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2012-04-06 21:52:34 +00:00
|
|
|
MyApp().run()
|