2015-06-28 64 views
0

我使用kivy和kv語言創建了一個簡單的應用程序界面。界面由搜索文本輸入,用於搜索確認的按鈕和「添加」按鈕組成。如果低於此,對於應用程序的內容TabbedPanel如何使TabbedPannel的選項卡填充所有水平空間?

#: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.")) 

這是設計輸出:

kivy regular app interface

TabbedPannel作品完美我想要的方式,但是我想的標籤,以填補所有的橫向空間。舉例來說,如果我用一個BoxLayoutButton S,他們擴大使用所有的橫向空間,就像我希望它:

BoxLayout: 
    orientation: 'horizontal' 
    size_hint_y: 0.1 
    Button: 
     text: 'tab1' 
    Button: 
     text: 'tab2' 
    Button: 
     text: 'tab3' 

Horizontal BoxLayout buttons

是否有辦法來調整TabbedPannel所以其TabbedPannelItem小號標籤可以使用所有的水平空間嗎?

回答

3

設置的TabbedPaneltab_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() 
+0

精彩!非常感謝你! – chicao

相關問題