P
P
pcdesign2018-02-04 15:29:33
Python
pcdesign, 2018-02-04 15:29:33

How to make vertical buttons in kivy accordion?

The code:

# -*- coding: utf8 -*-
from kivy.uix.accordion import Accordion, AccordionItem
from kivy.uix.label import Label
from kivy.app import App
from kivy.uix.button import Button

items = {
    "razdely": [
        {"text": "О жизни", "id": 1},
        {"text": "О Человеке", "id": 2},
        {"text": "О тесте", "id": 3}]
}


class AccordionApp(App):
    def build(self):
        root = Accordion(orientation='vertical')
        for x in items.get('razdely'):
            item = AccordionItem(title=x.get("text"))
            item.add_widget(Button(text="Кнопка N1"))
            item.add_widget(Button(text="Кнопка N2"))
            root.add_widget(item)
        return root


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

Result:
5a76fbafe8f36218364037.png
How to make it look like this:
5a76fc84657ec185016993.png
?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Mikhailov, 2018-02-05
@pcdesign

BoxLayout stick vertical where the buttons are.
From the documentation ( https://kivy.org/docs/api-kivy.uix.boxlayout.html#...

layout = BoxLayout(orientation='vertical')
btn1 = Button(text='Hello')
btn2 = Button(text='World')
layout.add_widget(btn1)
layout.add_widget(btn2)

for x in items.get('razdely'):
            item = AccordionItem(title=x.get("text"))
            #~ item.add_widget(Button(text="Кнопка N1"))
            #~ item.add_widget(Button(text="Кнопка N2"))
            #~ item.add_widget(layout)
            layout = BoxLayout(orientation='vertical')
            btn1 = Button(text='Hello')
            btn2 = Button(text='World')
            layout.add_widget(btn1)
            layout.add_widget(btn2)
            item.add_widget(layout)
            root.add_widget(item)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question