2017-07-12 48 views
1

你好,我在使用Kivy在python中使用GUI時遇到問題。我正在使用TabbedPanel。如何安排標籤,在Python中使用Kivy進入TabbedPanel

TabbedPanelItem: 
     text: 'apple' 
     BoxLayout: 
      Label: 
       text: 'Label1' 
      Entry: 
       text: 'Entry1' 
      CheckBox: 
       text: 'CheckBox1' 
      Button: 
       text: 'Button1' 
    TabbedPanelItem: 
     text: 'Grape' 
     BoxLayout: 
      Label: 
       text: 'Label1' 
      Button: 
       text: 'Button1' 
+0

您的KV的錯誤:'Entry'不是kivy類,它必須是' TextInput' – FJSevilla

回答

2

幾件事情:

  • ,你可以在第二內建方法只有一個build方法
  • 回報,是不正確的縮進,應該是相同for
  • 你總是可以只一個App類別不是class AccordionApp(App):class KivyGuiApp(App):

這裏是您的應用程序的縮小版本,從中應該能夠實現更多的從

''' 
TabbedPanel 
============ 

Test of the widget TabbedPanel. 
''' 

from kivy.app import App 
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem 
from kivy.lang import Builder 
from kivy.uix.checkbox import CheckBox 
from kivy.uix.accordion import Accordion, AccordionItem 
from kivy.uix.button import Button 
from kivy.app import App 


Builder.load_string(""" 

<Test>: 
    TabbedPanelItem: 
     text: 'apple' 
     BoxLayout: 
      Label: 
       text: 'Label1' 
      Label: 
       text: 'Entry1' 
      CheckBox: 
       text: 'CheckBox1' 
      Button: 
       text: 'Button1' 

""") 

class Test(TabbedPanel): 
    pass 

class KivyGuiApp(App): 

    def build(self): 
     test = Test() 
     acc = Accordion() 
     for x in range(5): 
      item = AccordionItem(title='Table %d' % x) 
      item.add_widget(Button(text='apple\n')) 
      item.add_widget(Button(text='Grape\n')) 
      item.add_widget(Button(text='Lemon\n')) 
      acc.add_widget(item) 
     panel = TabbedPanelItem() 
     panel.add_widget(acc) 

     test.add_widget(panel) 
     return test 



if __name__ == '__main__': 
    KivyGuiApp().run() 

enter image description here

+0

考慮upvoting或接受答案,如果它幫助或解決了你的問題。 – PalimPalim

+0

今晚我會有一些時間(英國時間),並會看看。你必須等到那個時候,對不起。如果我還應該對txt文件做些什麼,請讓他們訪問我。 – PalimPalim

+0

嘿@PalimPalim,你能幫我解決這些問題嗎?在此先感謝 – crazyDelight