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