我有一个简单的选项卡式应用程序。现在在每个选项卡中我都会有一个手风琴
我已经在* .kv文件中创建了布局。现在我的问题是(可能是个愚蠢的人,但是我对奇异果的工作方式还很陌生):如何在我创建的手风琴中添加项目和子项目。
在此示例中,我正在构建电视观看应用程序。因此,例如,直播电视将手风琴标题作为频道的组和频道的内部(我将从数据库中获得)]
这是我的python代码:
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.config import Config
from kivy.uix.accordion import Accordion, AccordionItem
class LiveTV(Accordion):
def ListItems(self):
root = Accordion()
for x in range(1, 3, 1):
item = AccordionItem(title='Page % d' % x)
root.add_widget(item)
return root
class Display(TabbedPanel):
def __init__(self, **kwargs):
super(Display, self).__init__(**kwargs)
rootAc = LiveTV.ListItems(self)
class IptvApp(App):
def build(self):
Config.set('graphics', 'width', '1366')
Config.set('graphics', 'height', '768')
Config.set('graphics', 'resizable', False)
# Change to auto for full screen app
Config.set('graphics', 'fullscreen', '0')
# Maximized for full resolution app
Config.set('graphics', 'window_state', 'visible')
# To remove right click orange dot (touch emulation)
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
Config.write()
return Display()
if __name__ == '__main__':
IptvApp().run()
这是我的* .kv文件
<Button>:
font_size: 40
color:0.3,0.6,0.7,1
size_hint: 0.4, 0.05
<Display>
tab_width: 600
size_hint: 1, 1
do_default_tab: False
TabbedPanelItem:
text: 'Live TV'
FloatLayout:
Accordion:
size_hint: 0.3,0.2
pos_hint: {"top": 1}
orientation: 'vertical'
AccordionItem:
title: 'Plot'
AccordionItem:
title: 'Number'
AccordionItem:
title: 'Another number'
TabbedPanelItem:
text: 'Video On Demand'
FloatLayout:
Label:
text: 'Second tab content area'
Button:
pos_hint: {"top": 0.4, "right": 0.7}
text: 'Button that does nothing'
TabbedPanelItem:
text: 'Series'
TabbedPanelItem:
text: 'Settings'
如何以编程方式确定我在* .kv文件中所做的那只手风琴的目标,以便我可以填充项目和子项目?
问候,
好,所以我知道了。对于所有到此为止的人,这是如何完成的:
在kv文件中,您要定位的元素以编程方式添加新的属性ID,例如,
Button:
id: btn_submit
并且在我的情况下,在父“类” <Display>
中定义该元素,即]
<Display>
btnSubmit: btn_submit
现在在定义了类Display的python代码中,您只需编写以下代码即可定位按钮:self.btnSubmit.*
例如,您可以添加add_widget或任何您想要的东西。