Expansion Panel

183 views
Skip to first unread message

coutinh...@gmail.com

unread,
Jun 3, 2022, 2:46:31 PM6/3/22
to Kivy users support
Hello.

Pardon my ignorance but...
How should I add more than one Content() using also a "for" in this example below?

Documentation example.

The idea is that some MDExpansionPanel have one or more Content()

Elias Coutinho

unread,
Jun 3, 2022, 7:46:48 PM6/3/22
to kivy-...@googlegroups.com
Does anyone have any tips on how to add multiple contents?

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/ed4df83b-eec0-45c0-9de2-c869383fe3e8n%40googlegroups.com.


--
Elias Coutinho.
Aprender sobre alguns assuntos é fundamental.
Aprender sobre Deus é indiscutivelmente o melhor conteúdo.

Elliot Garbus

unread,
Jun 4, 2022, 12:23:21 AM6/4/22
to kivy-...@googlegroups.com

The class only has one content attribute.  If you want multiple items on the expansion panel, set a content item to be a layout, and add the items.  Extending the example in the docs:

 

from kivy.lang import Builder

from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelThreeLine
from kivymd import images_path

KV =
'''
<Content>
    adaptive_height: True
    orientation: 'vertical'

    TwoLineIconListItem:
        text: "(050)-123-45-67"
        secondary_text: "Mobile"

        IconLeftWidget:
            icon: 'phone'
           
    TwoLineIconListItem:
        text: "Second Item Line One"
        secondary_text: "Second Item Line Two"



ScrollView:

    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''


class Content(MDBoxLayout):
   
'''Custom content.'''


class Test(MDApp):
   
def build(self):
       
return Builder.load_string(KV)

   
def on_start(self):
       
for i in range(10):
           
self.root.ids.box.add_widget(
                MDExpansionPanel(
                   
icon=f"{images_path}kivymd.png",
                   
content=Content(),
                   
panel_cls=MDExpansionPanelThreeLine(
                       
text="Text",
                       
secondary_text="Secondary text",
                       
tertiary_text="Tertiary text",
                    )
                )
            )


Test().run()
Message has been deleted

Elias Coutinho

unread,
Jun 4, 2022, 7:43:44 AM6/4/22
to kivy-...@googlegroups.com
I'm ashamed to say this but I'd like to add dynamically using the "for" loop.

It seems silly to many but for me it's news that I'm tied up.

Elliot Garbus

unread,
Jun 4, 2022, 11:05:14 AM6/4/22
to kivy-...@googlegroups.com

Here you go… The for loop in content adds 3 TwoLine items to the exapansion panel, the initial item is defined in kv.  You can move them all to the for loop.

 

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelThreeLine
from kivymd.uix.list import TwoLineListItem
from kivymd import images_path

KV =
'''

<Content>
    adaptive_height: True
    orientation: 'vertical'

    TwoLineIconListItem:
        text: "(050)-123-45-67"
        secondary_text: "Mobile"
        IconLeftWidget:
            icon: 'phone'

ScrollView:
    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''


class Content(MDBoxLayout):
   
'''Custom content.'''
   
def on_kv_post(self, base_widget):
       
for i in range(1, 4):
            w = TwoLineListItem(
text=f"Item {i} Line One", secondary_text="Line Two")
           
self.add_widget(w)



class Test(MDApp):
   
def build(self):
       
return Builder.load_string(KV)

   
def on_start(self):
       
for i in range(10):
           
self
.root.ids.box.add_widget(
                MDExpansionPanel(
                   
icon='pencil',
                   
content=Content(),
                   
panel_cls=MDExpansionPanelThreeLine(
                       
text="Text",
                       
secondary_text="Secondary text",
                        
tertiary_text="Tertiary text",
                    )
                )
            )


Test().run()

Elias Coutinho

unread,
Jun 5, 2022, 8:27:58 AM6/5/22
to kivy-...@googlegroups.com
We are definitely getting where I imagined.
What happens is that I will fill in this data by extracting this JSON below:

"Card": {
         "Invoice": {
           "20220602184756182705": {
             "0100251633": {
               "price": "92.07",
               "product_code": "000156",
               "quantity": "1000"
             },
             "01001BA476": {
               "price": "74.73",
               "product_code": "000003",
               "quantity": "100"
             }
           }
         }
}

where 20220602184756182705 I will show the key in MDExpansionPanelThreeLine (This is easy)
It's really hard to take its value to the Content() class.

Taking into account that I have several records of these.

*** Off topic question ***
How can you send hi light codes through the forum.

Elliot Garbus

unread,
Jun 5, 2022, 10:42:13 AM6/5/22
to kivy-...@googlegroups.com

*** Off topic question ***
How can you send hi light codes through the forum.

 

I have the messages from the forum set to my local email client.  I use the highlighter capability in the default Windows Email client.

 

Did you have a question about getting the JSON into the expansion panel?

Elias Coutinho

unread,
Jun 5, 2022, 11:04:02 AM6/5/22
to kivy-...@googlegroups.com
Yes, I would like the key 20220602184756182705 of this JSON to be displayed in the MDExpansionPanel and the values


{
              "0100251633": {
                "price": "92.07",
                "product_code": "000156",
                "quantity": "1000"
              },
...
...

be displayed in Content.

Elliot Garbus

unread,
Jun 5, 2022, 1:41:29 PM6/5/22
to kivy-...@googlegroups.com

I think this is what you are looking for…

As an FYI, when parsing JSON, I like to use pretty print to print the JSON, it makes it easier to understand when parsing.

 

 

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivymd.uix.list import ThreeLineListItem

KV =
'''

<Content>
    adaptive_height: True
    orientation: 'vertical'

<InvoicePanel>:
    icon: 'pencil'

           

ScrollView:
    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''

json_data = {'Card': {'Invoice': {'20220602184756182705': {'01001BA476': {'price': '74.73',
                                                                         
'product_code': '000003',
                                                                         
'quantity': '100'},
                                                           
'0100251633': {'price': '92.07',
                                                                         
'product_code': '000156',
                                                                         
'quantity': '1000'}}}}}


class InvoicePanel(MDExpansionPanel):
   
pass


class
Content(MDBoxLayout):
   
pass


class
Test(MDApp):
   
def build(self):
       
return Builder.load_string(KV)

   
def on_start(self):
       
# I am assuming you have multiple invoices per each card...
       
invoices = list(json_data['Card']['Invoice'].keys())
       
for invoice in invoices:
           
# add invoice as major item
           
cw = Content()  # fill in content as the data is parsed
           
ep = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {invoice}'),
                             
content=cw)
           
self.root.ids.box.add_widget(ep)
            line_items =
list(json_data['Card']['Invoice'][invoice].keys())
           
# self.root.ids.box.add_widget(ep)
           
for item in line_items:
                lines = [(k, v)
for k, v in json_data['Card']['Invoice'][invoice][item].items()]
               
# add content as 3 line item
               
cw.add_widget(ThreeLineListItem(text=f'Item: {item}{lines[0][0]}: {lines[0][1]}',
                                               
secondary_text=f'{lines[1][0]}: {lines[1][1]}',
                                               
tertiary_text=f'{lines[2][0]}: {lines[2][1]}'))


Test().run()

Elias Coutinho

unread,
Jun 6, 2022, 8:44:54 AM6/6/22
to kivy-...@googlegroups.com
Perfect bro!

I wasn't sure how to access another class in this case.

Everything as I expected!

Elias Coutinho

unread,
Jun 9, 2022, 2:57:51 PM6/9/22
to kivy-...@googlegroups.com
Hello,

Can I make the text centered?
I couldn't, so I added a button and incredibly it wasn't centered either.

I think the Content class doesn't have this feature.
What do you think?

Em dom., 5 de jun. de 2022 às 14:41, Elliot Garbus <elli...@cox.net> escreveu:

Elliot Garbus

unread,
Jun 9, 2022, 3:47:35 PM6/9/22
to kivy-...@googlegroups.com

The "Content Class” in the example below is an MDBoxLayout.

You would want the ThreeLineListItem to center the text.  Looking at the source code for kicyMD, the look the ThreeLine list item is set by it’s parent class.

It think it would be easiest to replace the ThreeLineListItem with a new class that contains an MDList that centers the data.

Elias Coutinho

unread,
Jun 9, 2022, 3:53:01 PM6/9/22
to kivy-...@googlegroups.com

Elliot Garbus

unread,
Jun 9, 2022, 4:35:23 PM6/9/22
to kivy-...@googlegroups.com

Yes you could use a Label on an MDLabel, or create a class that has multiple Labels.  You would want to draw a line under the text to have a look consistent with the ListItem classes.

Elias Coutinho

unread,
Jun 10, 2022, 7:23:22 PM6/10/22
to kivy-...@googlegroups.com
I used the following feature:

# Class created to allow alignment
class OneLineListItemAligned(OneLineListItem):
     def __init__(self, halign, **kwargs):
         super(OneLineListItemAligned, self).__init__(**kwargs)
         self.ids._lbl_primary.halign = halign


                     close_items = OneLineListItemAligned(
                         text='Close this order now?', md_bg_color=app.theme_cls.primary_dark, halign="center", font_style="H6")
                     cw.add_widget(close_items)

Elliot Garbus

unread,
Jun 10, 2022, 7:30:04 PM6/10/22
to kivy-...@googlegroups.com

Elias Coutinho

unread,
Jun 13, 2022, 2:46:58 PM6/13/22
to kivy-...@googlegroups.com
I have the following code all in python:



                     close_items = OneLineListItemAligned(
                         text='Close this order now?',
                         md_bg_color=app.theme_cls.primary_dark,
                         halign="center", font_style="H6")

                     #on_release=print("----------Click!")

How do I add this on_release or on_click event to this widget?

Elliot Garbus

unread,
Jun 13, 2022, 4:59:35 PM6/13/22
to kivy-...@googlegroups.com

The example below shows 3 ways to do it.

The on_release attribute needs to be assigned a callable.  You can use a lambda to create an anonymous function; you can use a method; or you can define a new class and specify the on_release in kv.

 

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

kv =
"""
<ReleaseButton>:
    on_release: print(f'{self.text} print from kv, instanced in python')

RootBoxLayout:
    orientation: 'vertical'
    Button:
        text: 'Button 0'
        on_release: print(f'{self.text} print from kv instanced in kv')
"""


class ReleaseButton(Button):
   
pass

class
RootBoxLayout(BoxLayout):
   
def on_kv_post(self, base_widget):
       
self.add_widget(Button(text='Button 1', on_release=lambda x:print(f'{x.text} instanced in python, print from lambda')))
       
self.add_widget(Button(text='Button 2', on_release=self.call_method))
       
self.add_widget(ReleaseButton(text='Button 3'))

   
def call_method(self, button):
       
print(f'{button.text} instanced in python, print in method')

class OnReleaseExamples(App):
   
def build(self):
       
return Builder.load_string(kv)

OnReleaseExamples().run()

Elias Coutinho

unread,
Jun 13, 2022, 6:26:44 PM6/13/22
to kivy-...@googlegroups.com
It wouldn't be exactly on a button, it would be on the onelinelistitem

Elliot Garbus

unread,
Jun 13, 2022, 7:08:19 PM6/13/22
to kivy-...@googlegroups.com
The techniques work the same. 

Sent from my iPhone

On Jun 13, 2022, at 3:26 PM, Elias Coutinho <coutinh...@gmail.com> wrote:



Elias Coutinho

unread,
Jun 13, 2022, 7:35:33 PM6/13/22
to kivy-...@googlegroups.com
By the method of the button 'Button 1' I can print the text of the button.

I just can't call the function close_order(self) as below:


close_items = OneLineListItemAligned(
       text='Close this order now?',
       md_bg_color=app.theme_cls.primary_dark,
       halign="center",
       font_style="H6",
       on_press=self.close_order())

No error occurs, it just doesn't display the OneLineListItem.

Elias Coutinho

unread,
Jun 13, 2022, 8:18:59 PM6/13/22
to kivy-...@googlegroups.com
Strangest thing for me!

On line 76 I have a normal function, it works by itself, the most perfect thing.



On line 145 I call this function, in this call two very strange and confusing situations happen:



1 - If I call the function with parentheses () the Expansion Panel items, which are in Content, do not appear and do not show any error.

2 - If I remove the parentheses it lists the Content but it gives a parameter error when calling the function.

What do you think?

Elliot Garbus

unread,
Jun 13, 2022, 9:16:47 PM6/13/22
to kivy-...@googlegroups.com

If you put the function in the constructor with  on_press=self.fechar_pedido(); then at the time you are making the enclosing call creating the OneListItemAligned, you will make the call to self.fechar_pedido(), and set on_press to the value that is returned by self.fechar_pedido().  In this case, that would be None.

 

What is the error you are seeing?

Charles longwe

unread,
Jun 13, 2022, 9:54:15 PM6/13/22
to kivy-...@googlegroups.com
Still don't understand  how to create expansion panel with different contents

Elliot Garbus

unread,
Jun 13, 2022, 10:02:32 PM6/13/22
to kivy-...@googlegroups.com

Charles,

I’ll be happy to put an example together for you.  I am assuming that you will get some data that you want to display.  My example will be more useful for you if the example uses the data as it is structured.   Do you have data that you want to display?

 

If you do not have data – let me know I’ll create an example.

Elliot Garbus

unread,
Jun 13, 2022, 11:26:41 PM6/13/22
to kivy-...@googlegroups.com

I’ve assumed the data is a list of tuples of the class name, and the details.  I hope this helps.

 

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty

class_data = [(
'Business 101', 'An introduction to key concepts'),
              (
'Business 201', 'An intermediate class'),
              (
'Business 301', 'A few focused an complex topics'),
              (
'Business 401', 'A detailed look a complex problems'),
              (
'Computer Science 101', 'An introduction to key concepts'),
              (
'Computer Science 201', 'An intermediate class'),
              (
'Computer Science 301', 'A few focused an complex topics'),
              (
'Computer Science 401', 'A detailed look a complex problems'),
              (
'Math 101', 'An introduction to key concepts'),
              (
'Math 201', 'An intermediate class'),
              (
'Math 301', 'A few focused an complex topics'),
              (
'Math 401', 'A detailed look a complex problems'),
              (
'Art 101', 'An introduction to key concepts'),
              (
'Art 201', 'An intermediate class'),
              (
'Art 301', 'A few focused an complex topics'),
              (
'Art 401', 'A detailed look a complex problems')]


KV =
'''
<ClassDetails>
    adaptive_height: True
    OneLineIconListItem:
        text: root.text
       
        IconLeftWidget:
            icon: 'star'


ScrollView:
    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''


class ClassDetails(MDBoxLayout):
    text = StringProperty()


class Test(MDApp):
   
def build(self):
       
return Builder.load_string(KV)

   
def on_start(self
):
       
for class_title, class_details in class_data:
           
self.root.ids.box.add_widget(
                MDExpansionPanel(
icon="pencil",
                                
content=ClassDetails(text=class_details),
                                
panel_cls=MDExpansionPanelOneLine(text=class_title)))


Test().run()

 

 

 

 

From: Elliot Garbus
Sent: Monday, June 13, 2022 7:02 PM
To: kivy-...@googlegroups.com
Subject: RE: [kivy-users] Expansion Panel

 

Charles,

I’ll be happy to put an example together for you.  I am assuming that you will get some data that you want to display.  My example will be more useful for you if the example uses the data as it is structured.   Do you have data that you want to display?

 

If you do not have data – let me know I’ll create an example.

 

 

 

Elias Coutinho

unread,
Jun 14, 2022, 2:45:55 PM6/14/22
to kivy-...@googlegroups.com
my code

def myprint(self):
print('---------- ok ----------')

def on_start(self):
for class_title, class_details in class_data:
self.root.ids.box.add_widget(
MDExpansionPanel(icon="pencil",
content=ClassDetails(text=class_details),
panel_cls=MDExpansionPanelOneLine(text=class_title, on_press=self.myprint())))


Test().run()

my traceback

--------- ok ----------
 Traceback (most recent call last):
   File "/home/elias/Documentos/PROGRAMACAO/1-PYTHON/1-KIVY/PROJETOS/1-KIVYMD/Kivy-Separado/code.py", line 61, in <module>
     Test().run()
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivy/app.py", line 954, in run
     self._run_prepare()
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivy/app.py", line 949, in _run_prepare
     self.dispatch('on_start')
   File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
   File "/home/elias/Documentos/PROGRAMACAO/1-PYTHON/1-KIVY/PROJETOS/1-KIVYMD/Kivy-Separado/code.py", line 58, in on_start
     panel_cls=MDExpansionPanelOneLine(text=class_title, on_press=self.myprint())))
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivymd/uix/list/list.py", line 898, in __init__
     super().__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivymd/uix/list/list.py", line 826, in __init__
     super().__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivymd/theming.py", line 1230, in __init__
     super().__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivy/uix/behaviors/button.py", line 121, in __init__
     super(ButtonBehavior, self).__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivy/uix/floatlayout.py", line 65, in __init__
     super(FloatLayout, self).__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivy/uix/layout.py", line 76, in __init__
     super(Layout, self).__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivymd/uix/behaviors/backgroundcolor_behavior.py", line 239, in __init__
     super().__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivymd/uix/behaviors/backgroundcolor_behavior.py", line 195, in __init__
     super().__init__(**kwarg)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivymd/uix/behaviors/elevation.py", line 851, in __init__
     super().__init__(**kwargs)
   File "/home/elias/Documentos/PROGRAMACAO/kivy_venv/lib/python3.9/site-packages/kivy/uix/widget.py", line 376, in __init__
     self.bind(**on_args)
   File "kivy/_event.pyx", line 444, in kivy._event.EventDispatcher.bind
 AssertionError: None is not callable

Elliot Garbus

unread,
Jun 14, 2022, 6:00:17 PM6/14/22
to kivy-...@googlegroups.com

Changes highlighted:

 

Builder.load_string(KV)

   
def myprint(self, expansion_panel):
       
print(expansion_panel.text)

       
print('---------- ok ----------')

   
def on_start(self):
       
for class_title, class_details in class_data:
           
self.root.ids.box.add_widget(
                MDExpansionPanel(
icon="pencil",
                                
content=ClassDetails(text
=class_details),
                                
panel_cls=MDExpansionPanelOneLine(text=class_title, on_press=self.myprint)))


Test().run()

Elias Coutinho

unread,
Jun 14, 2022, 6:27:12 PM6/14/22
to kivy-...@googlegroups.com
I hate to cause rework but I ended up writing the code incorrectly, I want to click on Content and the click action calls up a screen, has it print something...

Really in the way you showed it, it makes the action happen, but my desire is to click on the content and the action happens.

I apologize for confusing and misplaced my code.

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/_wyQpAhuwxw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/62a904e9.1c69fb81.26f90.699bSMTPIN_ADDED_MISSING%40gmr-mx.google.com.

Elliot Garbus

unread,
Jun 14, 2022, 6:36:23 PM6/14/22
to kivy-...@googlegroups.com
Try it yourself. If you get stuck, post the code. 

Sent from my iPhone

On Jun 14, 2022, at 3:27 PM, Elias Coutinho <coutinh...@gmail.com> wrote:



Elias Coutinho

unread,
Jun 15, 2022, 6:37:22 PM6/15/22
to kivy-...@googlegroups.com
My problem is that when I click on the content nothing happens.
I tried to use the logic you used earlier but no error happens.

Here's the code based on what you've given me.

Elliot Garbus

unread,
Jun 15, 2022, 6:46:25 PM6/15/22
to kivy-...@googlegroups.com

The content, is the ClassDetails class.  ClassDetails is derived from an MDBoxLayout.  If we want to have a response to an on_press event, we can add ButtonBehavior.

 

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty
from kivy.uix.behaviors import ButtonBehavior
class ClassDetails(ButtonBehavior, MDBoxLayout):
    text = StringProperty()


class Test(MDApp):
   
def build(self):
       
return
Builder.load_string(KV)

   
def myprint(self, obj):
       
print('---------- ok ----------')
       
print(obj.text)

   
def on_start(self):
       
for class_title, class_details in class_data:
           
self.root.ids.box.add_widget(
                MDExpansionPanel(
icon="pencil",
                                
content=ClassDetails(text=class_details, on_press=self.myprint),
                                
panel_cls=MDExpansionPanelOneLine(text=class_title)))


Test().run()

Elliot Garbus

unread,
Jun 15, 2022, 7:03:34 PM6/15/22
to kivy-...@googlegroups.com

Here are two other ways to add the on_press…

You could use the on_press event that is available in the components of ClassDetails, the OneLineIconListItem and the IconLeftWidet.

 

  1. Looking a the kv code, you can see that for the IconLeftWidget, the on_press event is used to call print directly.  I think for this use case this would be the more natural place to put on the on_press callback methods.

 

  1. Looking at the code for the ClassDetails method, notice and ObjectProperty was added, named “action”, in the constructor for MDExpansionPanel, action is set.

               In the kv code definition of Class detail, action is called.  If you had different callbacks you wanted to insert based on the data this might be a useful approach.

 

 

 

 

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty, ObjectProperty

class_data = [(
'Business 101', 'An introduction to key concepts'),
              (
'Business 201', 'An intermediate class'),
              (
'Business 301', 'A few focused an complex topics'),
              (
'Business 401', 'A detailed look a complex problems'),
              (
'Computer Science 101', 'An introduction to key concepts'),
              (
'Computer Science 201', 'An intermediate class'),
              (
'Computer Science 301', 'A few focused an complex topics'),
              (
'Computer Science 401', 'A detailed look a complex problems'),
              (
'Math 101', 'An introduction to key concepts'),
              (
'Math 201', 'An intermediate class'),
              (
'Math 301', 'A few focused an complex topics'),
              (
'Math 401', 'A detailed look a complex problems'),
              (
'Art 101', 'An introduction to key concepts'),
              (
'Art 201', 'An intermediate class'),
              (
'Art 301', 'A few focused an complex topics'),
              (
'Art 401', 'A detailed look a complex problems')]

KV =
'''
<ClassDetails>
    adaptive_height: True
    OneLineIconListItem:
        id: info_line
        text: root.text
        on_press: root.action()

        IconLeftWidget:
            icon: 'star'
            on_press: print(f'star pressed on line: {info_line.text}')


ScrollView:
    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''


class ClassDetails(MDBoxLayout):
    text = StringProperty()
    action = ObjectProperty()


class Test(MDApp):
   
def build(self):
       
return
Builder.load_string(KV)

   
def my_print(self):
       
print('You clicked on the information line')

   
def on_start(self):
       
for class_title, class_details in class_data:
           
self.root.ids.box.add_widget(
                MDExpansionPanel(
icon="pencil",
                                
content=ClassDetails(text=class_details, action=self.my_print),
                                
panel_cls=MDExpansionPanelOneLine(text=class_title)))


Test().run()

Elias Coutinho

unread,
Jun 17, 2022, 5:31:20 PM6/17/22
to kivy-...@googlegroups.com
Hello,

I've tried everything to add an event or a button that executes a function, I've seen your examples but I always get confused at some points.

In this example you gave me I can understand everything, I just can't make the panel execute the function.

It must be in this code model because the ones I've seen create only one content, and in my case the amount of content is variable.

Em qua., 15 de jun. de 2022 às 21:06, Elias Coutinho <coutinh...@gmail.com> escreveu:
Perfect!



--
Elias Coutinho.
Aprender sobre alguns assuntos é fundamental.
Aprender sobre Deus é indiscutivelmente o melhor conteúdo.
Reply all
Reply to author
Forward
0 new messages