如何让 TabbedPannel 的 tab 全部水平填满 space?
How to make TabbedPannel's tabs fill all horizontal space?
我正在使用 kivy 和 kv 语言创建一个简单的应用程序界面。该界面由搜索文本输入、搜索确认按钮和 'add' 按钮组成。在此下方,应用内容有一个 TabbedPanel
:
#:import label kivy.uix.label
#:import sla kivy.adapters.simplelistadapter
<MenuScreen>:
AnchorLayout:
anchor_x: 'left'
anchor_y: 'top'
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
size_hint_y: 0.15
TextInput:
text: 'Search'
Button:
size_hint_x: 0.2
text: 'Ok'
Button:
size_hint_x: 0.2
text: '+'
TabbedPanel:
do_default_tab: False
TabbedPanelItem:
text: 'tab1'
ListView:
orientation: 'vertical'
adapter:
sla.SimpleListAdapter(
data=["Item #{0}".format(i) for i in range(100)],
cls=label.Label)
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."))
这是设计输出:
TabbedPannel
完全按照我想要的方式工作,但是我希望选项卡填满所有水平 space。例如,如果我将 BoxLayout
与 Button
一起使用,它们将使用所有水平 space 展开,正如我想要的那样:
BoxLayout:
orientation: 'horizontal'
size_hint_y: 0.1
Button:
text: 'tab1'
Button:
text: 'tab2'
Button:
text: 'tab3'
有没有办法调整 TabbedPannel
以便它的 TabbedPannelItem
标签可以使用所有水平 space?
将 TabbedPanel
的 tab_width
属性 设置为其宽度除以标签数:
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.lang import Builder
Builder.load_string("""
<Test>:
do_default_tab: False
tab_width: self.size[0]/len(self.tab_list)
TabbedPanelItem:
text: 'tab 1'
TabbedPanelItem:
text: 'tab2'
TabbedPanelItem:
text: 'tab3'
""")
class Test(TabbedPanel):
pass
class TabbedPanelApp(App):
def build(self):
return Test()
if __name__ == '__main__':
TabbedPanelApp().run()
我正在使用 kivy 和 kv 语言创建一个简单的应用程序界面。该界面由搜索文本输入、搜索确认按钮和 'add' 按钮组成。在此下方,应用内容有一个 TabbedPanel
:
#:import label kivy.uix.label
#:import sla kivy.adapters.simplelistadapter
<MenuScreen>:
AnchorLayout:
anchor_x: 'left'
anchor_y: 'top'
BoxLayout:
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
size_hint_y: 0.15
TextInput:
text: 'Search'
Button:
size_hint_x: 0.2
text: 'Ok'
Button:
size_hint_x: 0.2
text: '+'
TabbedPanel:
do_default_tab: False
TabbedPanelItem:
text: 'tab1'
ListView:
orientation: 'vertical'
adapter:
sla.SimpleListAdapter(
data=["Item #{0}".format(i) for i in range(100)],
cls=label.Label)
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."))
这是设计输出:
TabbedPannel
完全按照我想要的方式工作,但是我希望选项卡填满所有水平 space。例如,如果我将 BoxLayout
与 Button
一起使用,它们将使用所有水平 space 展开,正如我想要的那样:
BoxLayout:
orientation: 'horizontal'
size_hint_y: 0.1
Button:
text: 'tab1'
Button:
text: 'tab2'
Button:
text: 'tab3'
有没有办法调整 TabbedPannel
以便它的 TabbedPannelItem
标签可以使用所有水平 space?
将 TabbedPanel
的 tab_width
属性 设置为其宽度除以标签数:
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.lang import Builder
Builder.load_string("""
<Test>:
do_default_tab: False
tab_width: self.size[0]/len(self.tab_list)
TabbedPanelItem:
text: 'tab 1'
TabbedPanelItem:
text: 'tab2'
TabbedPanelItem:
text: 'tab3'
""")
class Test(TabbedPanel):
pass
class TabbedPanelApp(App):
def build(self):
return Test()
if __name__ == '__main__':
TabbedPanelApp().run()