Tuesday, August 5, 2014

57. Accordion

The Accordion offers dividers to select between different screens.




The Accordion widget is used for the root. The App class is needed for any application.




We have to have a subclass of the App class.


# ex57.py
from kivy.uix.accordion import Accordion
from kivy.app import App

class Ex57(Accordion):
    pass

class Ex57App(App):
    def build(self):
        return Ex57()
    
if __name__ == '__main__':
    Ex57App().run()



In the kv file, the MyImage dynamic class is created and it allows for a stretchable image. The orientation of the Accordion is 'vertical'. The default is 'horizontal'.




The first 3 screens are the images p1, p2 and p3.




The next 2 screens corresponds to images p4 and p5.


# ex57.kv
<MyImage@Image>:
    keep_ratio: False
    allow_stretch: True

<Ex57>:
    orientation: 'vertical'
    AccordionItem:
        title: 'The Basin'
        MyImage:
            source: 'p1.png'
    AccordionItem:
        title: 'Boise Rock'
        MyImage:
            source: 'p2.png'
    AccordionItem:
        title: 'Old Forest'
        MyImage:
            source: 'p3.png'
    AccordionItem:
        title: 'Old Man of the Mountain'
        MyImage:
            source: 'p4.png'
    AccordionItem:
        title: 'Flume Gorge'
        MyImage:
            source: 'p5.png'



In this result, we select the p3 image. Any widgets, including layouts, could be used for the individual Accordion items. Besides the orientation, we can also change the animation transition effects between different screens.




11 comments:

  1. Python:

    Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    https://www.emexotechnologies.com/online-courses/python-training-in-electronic-city/

    ReplyDelete
  2. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    Python Training in electronic city

    ReplyDelete
  3. This article is awesome. meanwhile I have also written one article on Monitors and technology. So if you want to check it out then you can Click here for more information related to Monitors

    ReplyDelete
  4. I'm extremely impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you modify it yourself? Either way keep up the excellent quality writing, it’s rare to see a great blog like this one today..apple kundenservice berlin

    ReplyDelete