How do I programmatically add an AccordionItem to an Accordion?

I have a test application which contains an Accordion. I want to be able to add items to the Accordion from within my python code.

Here is the relevant kv code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><LayoutTest>:
BoxLayout:
id: mainBox
BoxLayout:
orientation: 'vertical'
canvas:
Color:
rgba: 0.16, 0.11, 0, 1 # brownish color
Rectangle:
pos: self.pos
size: self.size
TabbedPanel:
id: tp
do_default_tab: False
TabbedPanelItem:
id: tab_1
text: 'Tab1R'
on_release: app.showTab1R()
ListView:
id: tab1_list
orientation: 'vertical'
<ListItem@AccordionItem>:
title: '2024/12/20 22:00 <some text>'
BoxLayout:
orientation: 'vertical'
Label:
text: 'Type 1'
text_size: self.width, None
Label:
text: 'Content 3'
text_size: self.width, None
<ListView@BoxLayout>:
Accordion:
id: accordyN
orientation: 'vertical'
AccordionItem:
title: '2024/12/20 00:00 <some text>'
BoxLayout:
orientation: 'vertical'
size_hint_y: None
# height: self.minimum_height
# height: type_label.height + content_label.height
valign: 'top'
Label:
id: type_label
text: 'Type 1'
text_size: self.size
halign: 'left'
valign: 'top'
Label:
id: content_label
text: 'Content 1'
text_size: self.size
halign: 'left'
valign: 'top'
AccordionItem:
title: '2024/12/20 09:00 <some text>'
BoxLayout:
orientation: 'vertical'
Label:
text: 'Type 1'
text_size: self.width, self.height
Label:
text: 'Content 2'
text_size: self.width, self.height
</code>
<code><LayoutTest>: BoxLayout: id: mainBox BoxLayout: orientation: 'vertical' canvas: Color: rgba: 0.16, 0.11, 0, 1 # brownish color Rectangle: pos: self.pos size: self.size TabbedPanel: id: tp do_default_tab: False TabbedPanelItem: id: tab_1 text: 'Tab1R' on_release: app.showTab1R() ListView: id: tab1_list orientation: 'vertical' <ListItem@AccordionItem>: title: '2024/12/20 22:00 <some text>' BoxLayout: orientation: 'vertical' Label: text: 'Type 1' text_size: self.width, None Label: text: 'Content 3' text_size: self.width, None <ListView@BoxLayout>: Accordion: id: accordyN orientation: 'vertical' AccordionItem: title: '2024/12/20 00:00 <some text>' BoxLayout: orientation: 'vertical' size_hint_y: None # height: self.minimum_height # height: type_label.height + content_label.height valign: 'top' Label: id: type_label text: 'Type 1' text_size: self.size halign: 'left' valign: 'top' Label: id: content_label text: 'Content 1' text_size: self.size halign: 'left' valign: 'top' AccordionItem: title: '2024/12/20 09:00 <some text>' BoxLayout: orientation: 'vertical' Label: text: 'Type 1' text_size: self.width, self.height Label: text: 'Content 2' text_size: self.width, self.height </code>
<LayoutTest>:
    BoxLayout:
        id: mainBox
        BoxLayout:
            orientation: 'vertical'
            canvas:
                Color:
                    rgba: 0.16, 0.11, 0, 1  # brownish color
                Rectangle:
                    pos: self.pos
                    size: self.size

            TabbedPanel:
                id: tp
                do_default_tab: False

                TabbedPanelItem:
                    id: tab_1
                    text: 'Tab1R'
                    on_release: app.showTab1R()
                    ListView:
                        id: tab1_list
                        orientation: 'vertical'

<ListItem@AccordionItem>:
    title: '2024/12/20  22:00    <some text>'
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Type 1'
            text_size: self.width, None
        Label:
            text: 'Content 3'
            text_size: self.width, None

<ListView@BoxLayout>:
    Accordion:
        id: accordyN
        orientation: 'vertical'

        AccordionItem:
            title: '2024/12/20  00:00    <some text>'
            BoxLayout:
                orientation: 'vertical'
                size_hint_y: None
                # height: self.minimum_height
                # height: type_label.height + content_label.height
                valign: 'top'
                Label:
                    id: type_label
                    text: 'Type 1'
                    text_size: self.size
                    halign: 'left'
                    valign: 'top'
                Label:
                    id: content_label
                    text: 'Content 1'
                    text_size: self.size
                    halign: 'left'
                    valign: 'top'

        AccordionItem:
            title: '2024/12/20  09:00    <some text>'
            BoxLayout:
                orientation: 'vertical'
                Label:
                    text: 'Type 1'
                    text_size: self.width, self.height
                Label:
                    text: 'Content 2'
                    text_size: self.width, self.height

Using this layout, my application can display the Accordion, as well as the two sample AccordionItems shown above.

In my Python code, I somehow need to access the Accordion in order to add widgets to it. Here’s my code which doesn’t work:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>...
def showTab1R(self):
self.updateList(None)
def updateList(self):
entry = ListItem(title='2024/12/20 22:00 <some text>')
mainBox.accordyN.add_widget()
</code>
<code>... def showTab1R(self): self.updateList(None) def updateList(self): entry = ListItem(title='2024/12/20 22:00 <some text>') mainBox.accordyN.add_widget() </code>
...
    def showTab1R(self):
        self.updateList(None)

    def updateList(self):
        entry = ListItem(title='2024/12/20  22:00    <some text>')
        mainBox.accordyN.add_widget()

In the Python code above, ListItem and mainBox are unrecognized (‘not defined’). How do I access these kv widgets from my Python code?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật