You are adding AccordionItem
s directly to the carousel
. You need to add item
s to root
and outside the for
loop add root
to the carousel
.
Kivy Accordion layout inside a Carousel
题
New to Kivy, but absolutely loving it. I've been toying with some of the different layouts and I'm trying to put an accordion on the second page of a carousel. The first page of the carousel is just a label and it works fine.
The problem is when I slide to the second page the accordion is not lined up like it should be. It's very zoomed in and the labels are off to the side. I can't even see all the items in it. I've attached a picture of the outcome.
Here is my code...
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.uix.label import Label
from kivy.app import App
from kivy.factory import Factory
from kivy.uix.carousel import Carousel
class Example1(App):
def build(self):
carousel = Carousel(direction='right')
upcoming = Label(text="This is a boring label")
carousel.add_widget(upcoming)
self.testDictionary = {"Test1": "Hello World", "Test2": "This is a test", "Test3": "To See how this formats"}
root = Accordion(anim_duration=1.5, orientation='vertical')
for verseLoc, verse in self.testDictionary.iteritems():
item = AccordionItem(title=verseLoc)
item.add_widget(Label(text=verse, text_size=(200, None)))
carousel.add_widget(item)
return carousel
Example1().run()
^How it looks by itself^ ^how it looks inside a carousel
解决方案
不隶属于 StackOverflow