0
我尝试提取可关闭的代码TabbedPanel
from github here。Kivy可关闭TabbedPanel
它工作正常,但标签的内容也不会被清除,只是标题。 如何在关闭时删除Tab的内容?
from kivy.app import App
from kivy.animation import Animation
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader
from kivy.factory import Factory
from kivy.lang import Builder
class CloseableHeader(TabbedPanelHeader):
pass
class TestTabApp(App):
def build(self):
return Builder.load_string('''
TabbedPanel:
do_default_tab: False
FloatLayout:
BoxLayout:
id: tab_1_content
Label:
text: 'Palim 1'
BoxLayout:
id: tab_2_content
Label:
text: 'Palim 2'
BoxLayout:
id: tab_3_content
Label:
text: 'Palim 3'
CloseableHeader:
text: 'tab1'
panel: root
content: tab_1_content.__self__
CloseableHeader:
text: 'tab2'
panel: root
content: tab_2_content.__self__
CloseableHeader:
text: 'tab3'
panel: root
content: tab_3_content.__self__
<CloseableHeader>
color: 0,0,0,0
disabled_color: self.color
# variable tab_width
text: 'tabx'
size_hint_x: None
width: self.texture_size[0] + 40
BoxLayout:
pos: root.pos
size_hint: None, None
size: root.size
padding: 3
Label:
id: lbl
text: root.text
BoxLayout:
size_hint: None, 1
orientation: 'vertical'
width: 22
Button:
on_press:
root.panel.remove_widget(root)
''')
if __name__ == '__main__':
TestTabApp().run()
是我希望看到的选项卡1,现在我仍然会看到TAB2的内容。
不幸的是,这只会清除小部件,但我希望如果关闭tab2,tab1会自动显示。 – PalimPalim
我没有设法做的唯一事情是自动显示另一个标签... –
@PalimPalim是否有效? –