TabbedPanel
Modulo: kivy.uix.tabbedpanel
importação: from kivy.uix.tabbedpanel import TabbedPanel
Uso:
O widget Tabbed Panel gerencia diferentes widgets em abas, com uma area de cabeçalho, que funciona como botão de seleção para escolhermos uma aba, a aba atual aparecera com uma borda destacada.
Exemplo simples:
''' TabbedPanel ============ Test of the widget TabbedPanel. ''' from kivy.app import App from kivy.uix.tabbedpanel import TabbedPanel from kivy.lang import Builder Builder.load_string(""" <Test>: size_hint: .5, .5 pos_hint: {'center_x': .5, 'center_y': .5} do_default_tab: False TabbedPanelItem: text: 'first tab' Label: text: 'First tab content area' TabbedPanelItem: text: 'tab2' BoxLayout: Label: text: 'Second tab content area' Button: text: 'Button that does nothing' TabbedPanelItem: text: 'tab3' RstDocument: text: '\\n'.join(("Hello world", "-----------", "You are in the third tab.")) """) class Test(TabbedPanel): pass class TabbedPanelApp(App): def build(self): return Test() if __name__ == '__main__': TabbedPanelApp().run()
Nota:
Uma nova classe TabbedPanelItem foi adicionada na versão 1.5.0 para conveniência. Então agora você pode adicionar um TabbedPanelItem para um TabbedPanel e o seu conteudo será exibido.
Uma nova classe TabbedPanelItem foi adicionada na versão 1.5.0 para conveniência. Então agora você pode adicionar um TabbedPanelItem para um TabbedPanel e o seu conteudo será exibido.
Customizando um TabbedPanel
Você pode escolher uma posicção para as abas serem exibidas:ex: tab_pos = 'top_mid'
Uma aba invidivual é chamada de TabbedPanelHeader. Ela é um botão especial que contem uma propriedade de conteudo, você pode adicionar um TabbedPanelHeader primeiro, edefinir seu conteudo separadamente:
tp = TabbedPanel()
th = TabbedPanelHeader(text='Tab2')
tp.add_widget(th)
th.content = your_content_instance
Isso é um conteudo "compartilhado" da área ativa, para todas as abas, sua aplicação é responsavel por adicionar o conteudoindividual das abas e por gerencia-las, mas não é responsavel por alternar entre os conteúdos, o painel de abas alterna entre as abas usando uma ação (action).
Isso é por padrão uma aba adicionada onde o painel de abas é instanciado.
Guias adicionadas individualmente como acima são adicionadas além da guia padrão. Assim, dependendo das suas necessidades e design, você poderá personalizar a guia padrão:
tp.default_tab_text = 'Algo especifico'
tp.bind(default_tab = meu_comando_de_retorno)
traduzindo ainda.
It’s important to note that by default,
default_tab_cls
is of type
TabbedPanelHeader
and thus has the same properties as other tabs.Since 1.5.0, it is now possible to disable the creation of the
default_tab
by setting do_default_tab
to False.Tabs and content can be removed in several ways:
tp.remove_widget(widget/tabbed_panel_header)
or
tp.clear_widgets() # to clear all the widgets in the content area
or
tp.clear_tabs() # to remove the TabbedPanelHeaders
tp.content.children
tp.tab_list
background_color = (1, 0, 0, .5) #50% translucent red
border = [0, 0, 0, 0]
background_image = 'path/to/background/image'
tab_header_instance.background_normal = 'path/to/tab_head/img'
tab_header_instance.background_down = 'path/to/tab_head/img_pressed'
<TabbedPanelStrip>
canvas:
Color:
rgba: (0, 1, 0, 1) # green
Rectangle:
size: self.size
pos: self.pos
-
class
kivy.uix.tabbedpanel.
StripLayout
(**kwargs)¶Added in 1.8.0 - Bases:
kivy.uix.gridlayout.GridLayout
The main layout that is used to house the entire tabbedpanel strip including the blank areas in case the tabs don’t cover the entire width/height.
-
background_image
¶Added in 1.8.0 - Background image to be used for the Strip layout of the TabbedPanel.
background_image
is aStringProperty
and defaults to a transparent image.
-
border
¶Added in 1.8.0 - Border property for the
background_image
.
border
is aListProperty
and defaults to [4, 4, 4, 4]
-
-
class
kivy.uix.tabbedpanel.
TabbedPanel
(**kwargs)¶Added in 1.3.0 - Bases:
kivy.uix.gridlayout.GridLayout
The TabbedPanel class. See module documentation for more information.
-
add_widget
(widget, index=0)¶Added in 1.3.0 - Add a new widget as a child of this widget.
Parameters: - widget:
Widget
- Widget to add to our list of children.
- index: int, defaults to 0
- Index to insert the widget in the list. Notice that the default of 0 means the widget is inserted at the beginning of the list and will thus be drawn on top of other sibling widgets. For a full discussion of the index and widget hierarchy, please see the Widgets Programming Guide.New in version 1.0.5.
- canvas: str, defaults to None
- Canvas to add widget’s canvas to. Can be ‘before’, ‘after’ or None for the default canvas.New in version 1.9.0.
>>> from kivy.uix.button import Button >>> from kivy.uix.slider import Slider >>> root = Widget() >>> root.add_widget(Button()) >>> slider = Slider() >>> root.add_widget(slider)
- widget:
-
background_color
¶Added in 1.3.0 - Background color, in the format (r, g, b, a).
background_color
is aListProperty
and defaults to [1, 1, 1, 1].
-
background_disabled_image
¶Added in 1.8.0 - Background image of the main shared content object when disabled.
background_disabled_image
is aStringProperty
and defaults to ‘atlas://data/images/defaulttheme/tab’.
-
background_image
¶Added in 1.3.0 - Background image of the main shared content object.
background_image
is aStringProperty
and defaults to ‘atlas://data/images/defaulttheme/tab’.
-
border
¶Added in 1.3.0 - Border used for
BorderImage
graphics instruction, used itself forbackground_image
. Can be changed for a custom background.
It must be a list of four values: (bottom, right, top, left). Read the BorderImage instructions for more information.
border
is aListProperty
and defaults to (16, 16, 16, 16)
-
clear_widgets
(**kwargs)¶Added in 1.3.0 - Remove all (or the specified)
children
of this widget. If the ‘children’ argument is specified, it should be a list (or filtered list) of children of the current widget.
Changed in version 1.8.0: The children argument can be used to specify the children you want to remove.
-
content
¶Added in 1.3.0 - This is the object holding (current_tab’s content is added to this)
the content of the current tab. To Listen to the changes in the content
of the current tab, you should bind to current_tabs content property.
content
is anObjectProperty
and defaults to ‘None’.
-
current_tab
¶Added in 1.4.0 - Links to the currently selected or active tab.
current_tab
is anAliasProperty
, read-only.
-
default_tab
¶Added in 1.3.0 - Holds the default tab.
NoteFor convenience, the automatically provided default tab is deleted when you change default_tab to something else. As of 1.5.0, this behaviour has been extended to every default_tab for consistency and not just the automatically provided one.default_tab
is anAliasProperty
.
-
default_tab_cls
¶Added in 1.4.0 - Specifies the class to use for the styling of the default tab.
Warningdefault_tab_cls should be subclassed from TabbedPanelHeaderdefault_tab_cls
is anObjectProperty
and defaults to TabbedPanelHeader. If you set a string, theFactory
will be used to resolve the class.
Changed in version 1.8.0: TheFactory
will resolve the class if a string is set.
-
default_tab_content
¶Added in 1.3.0 - Holds the default tab content.
default_tab_content
is anAliasProperty
.
-
default_tab_text
¶Added in 1.3.0 - Specifies the text displayed on the default tab header.
default_tab_text
is aStringProperty
and defaults to ‘default tab’.
-
do_default_tab
¶Added in 1.5.0 - Specifies whether a default_tab head is provided.
do_default_tab
is aBooleanProperty
and defaults to ‘True’.
-
remove_widget
(widget)¶Added in 1.3.0 - Remove a widget from the children of this widget.
Parameters: - widget:
Widget
- Widget to remove from our children list.
>>> from kivy.uix.button import Button >>> root = Widget() >>> button = Button() >>> root.add_widget(button) >>> root.remove_widget(button)
- widget:
-
strip_border
¶Added in 1.8.0 - Border to be used on
strip_image
.
strip_border
is aListProperty
and defaults to [4, 4, 4, 4].
-
strip_image
¶Added in 1.8.0 - Background image of the tabbed strip.
strip_image
is aStringProperty
and defaults to a empty image.
-
switch_to
(header, do_scroll=False)¶Added in 1.3.0 - Switch to a specific panel header.
Changed in version 1.10.0.If used with do_scroll=True, it scrolls to the header’s tab too.
-
tab_height
¶Added in 1.3.0 - Specifies the height of the tab header.
tab_height
is aNumericProperty
and defaults to 40.
-
tab_list
¶Added in 1.3.0 - List of all the tab headers.
tab_list
is anAliasProperty
and is read-only.
-
tab_pos
¶Added in 1.3.0 - Specifies the position of the tabs relative to the content.
Can be one of: left_top, left_mid, left_bottom, top_left,
top_mid, top_right, right_top, right_mid, right_bottom,
bottom_left, bottom_mid, bottom_right.
tab_pos
is anOptionProperty
and defaults to ‘top_left’.
-
tab_width
¶Added in 1.3.0 - Specifies the width of the tab header.
tab_width
is aNumericProperty
and defaults to 100.
-
-
class
kivy.uix.tabbedpanel.
TabbedPanelContent
(**kwargs)¶Added in 1.3.0 - Bases:
kivy.uix.floatlayout.FloatLayout
The TabbedPanelContent class.
-
class
kivy.uix.tabbedpanel.
TabbedPanelHeader
(**kwargs)¶Added in 1.3.0 - Bases:
kivy.uix.togglebutton.ToggleButton
A Base for implementing a Tabbed Panel Head. A button intended to be used as a Heading/Tab for a TabbedPanel widget.
You can use this TabbedPanelHeader widget to add a new tab to a TabbedPanel.
-
content
¶Added in 1.3.0 - Content to be loaded when this tab header is selected.
content
is anObjectProperty
and defaults to None.
-
on_touch_down
(touch)¶Added in 1.3.0 - Receive a touch down event.
Parameters: - touch:
MotionEvent
class - Touch received. The touch is in parent coordinates. See
relativelayout
for a discussion on coordinate systems.
Returns: bool If True, the dispatching of the touch event will stop. If False, the event will continue to be dispatched to the rest of the widget tree. - touch:
-
-
class
kivy.uix.tabbedpanel.
TabbedPanelItem
(**kwargs)¶Added in 1.5.0 - Bases:
kivy.uix.tabbedpanel.TabbedPanelHeader
This is a convenience class that provides a header of type TabbedPanelHeader and links it with the content automatically. Thus facilitating you to simply do the following in kv language:
<TabbedPanel>: # ...other settings TabbedPanelItem: BoxLayout: Label: text: 'Second tab content area' Button: text: 'Button that does nothing'
-
add_widget
(widget, index=0)¶Added in 1.5.0 - Add a new widget as a child of this widget.
Parameters: - widget:
Widget
- Widget to add to our list of children.
- index: int, defaults to 0
- Index to insert the widget in the list. Notice that the default of 0 means the widget is inserted at the beginning of the list and will thus be drawn on top of other sibling widgets. For a full discussion of the index and widget hierarchy, please see the Widgets Programming Guide.New in version 1.0.5.
- canvas: str, defaults to None
- Canvas to add widget’s canvas to. Can be ‘before’, ‘after’ or None for the default canvas.New in version 1.9.0.
>>> from kivy.uix.button import Button >>> from kivy.uix.slider import Slider >>> root = Widget() >>> root.add_widget(Button()) >>> slider = Slider() >>> root.add_widget(slider)
- widget:
-
remove_widget
(widget)¶Added in 1.5.0 - Remove a widget from the children of this widget.
Parameters: - widget:
Widget
- Widget to remove from our children list.
>>> from kivy.uix.button import Button >>> root = Widget() >>> button = Button() >>> root.add_widget(button) >>> root.remove_widget(button)
- widget:
-
-
class
kivy.uix.tabbedpanel.
TabbedPanelStrip
(**kwargs)¶Added in 1.3.0 - Bases:
kivy.uix.gridlayout.GridLayout
A strip intended to be used as background for Heading/Tab. This does not cover the blank areas in case the tabs don’t cover the entire width/height of the TabbedPanel(useStripLayout
for that).
-
tabbed_panel
¶Added in 1.3.0 - Link to the panel that the tab strip is a part of.
tabbed_panel
is anObjectProperty
and defaults to None .
-
-
exception
kivy.uix.tabbedpanel.
TabbedPanelException
¶Added in 1.3.0 - Bases:
Exception
The TabbedPanelException class.
0 Comentários