我们正在Kivy应用程序的主菜单中使用手风琴,并正在解决两个问题:
1)当我们打开一个手风琴项目,当我们再次按下该项目时,该项目不会崩溃。唯一能让它倒塌的方法是按另一个手风琴项目。这仅仅是Kivy的手风琴小部件的工作方式还是有办法改变这个设置?在
2)当我们的屏幕打开时,列表中的最后一个手风琴项目从开始就显示为展开。我们如何使这个手风琴项目装载在一个折叠的位置?我们尝试在我们的kv文件中设置collapse:True,但这没用
我们的kv代码如下:
GeneralBoxLayout:
GridLayout1:
BodyBoxLayout:
rows: 2
GeneralTextGridLayout:
size_hint: (1,.07)
GeneralTextLabel:
text: '[color=0046C3]Select a topic[/color]'
ScrollView:
size_hint: (1,.93)
HomeGridLayout:
Accordion:
orientation: "vertical"
AccordionItem:
title: "Topic 1"
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
size_hint_y: None
height: '50dp'
font_size: '12sp'
border: 20, 20, 20, 20
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 2'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 3'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 4'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 5'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 6'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 7'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 8'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
GameButton0:
text: 'Game 1'
AccordionItem:
title: 'Topic 9'
background_normal: 'img/blue_button5.png'
background_selected: 'img/blue_button5.png'
collapse: True
GameButton0:
text: ' Game 1'
FooterGridLayout:
ReturnButton:
text: 'Logout'
谢谢
我不知道如何解决你的第一个问题,但我做了什么,使手风琴开始在扩大的位置是使用一个折叠:假标志我的第一个手风琴项目。在
所以,我意识到这个问题已经有5年了,但我今天自己也遇到了这个问题,通过创建自定义的}类,重写},我就能够让它工作了(至少对于我正在做的工作)。我只是从它们的基类复制并粘贴了这些方法,并做了一些下面提到的小更改。在
^{pr2}$Accordion
和{Accordion._do_layout
和{请注意,kv文件包含kivy模板。我不确定这些是如何工作的,kivy模板是不推荐使用的。但是,如果您想更改打开/关闭
PopUpAccordionItem
的按钮的外观,这是(至少一种方法)可以做到的方法。还要注意,我们通过传递模板名的字符串值将PopUpAccordionItem
连接到__init__
中的模板。。。这看起来很奇怪但很管用。在相关问题 更多 >
编程相关推荐