简体   繁体   中英

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

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'

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())
on_release:app.root.current = "Name of the Widget"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM