How to open MDCard when I press a button in kivy(python)?

Question:

I have a button on a screen, I want to open MDCard when I press this button. I wrote this code the same as Popup but the MDCard object has no attribute ‘open’. How can I open MyMDCard

#: import Factory kivy.factory.Factory

<Second>:
    FloatLayout:
        Button:
            text:"Open MDCard"
            size_hint: .3, .07 
            pos_hint: {"x":.07, "y":0.25} 
            on_release: Factory.MyMDCard().open()

<MyMDCard@MDCard>
    orientation: "vertical"
    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'Blue.png'

    FloatLayout:    
        Button:
            id: 'change'
Asked By: mehdi alizade

||

Answers:

The MDCard is not a Popup, it is just another Widget. So to display the MDCard, you must add it to your App typically by using the add_widget() method of some container that is already in your App. For example, instead of:

on_release: Factory.MyMDCard().open()

try:

on_release: root.add_widget(Factory.MyMDCard())
Answered By: John Anderson
on_release:app.root.current = "Name of the Widget"
Answered By: Jgf
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.