'How to set the title and text property of a kivymd MDCard class
I'm trying to change the text of an MDCard class in a for loop by creating various instances of the card in the for loop but I cant seem to manipulate the title and text properties of the MDCard class in the for loop, what might I be doing wrong?
Thank you in advance
from kivy.properties import StringProperty
from kivymd.app import MDApp
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.card import MDCard
from kivymd.uix.label import MDLabel
from kivy.lang import Builder
from kivy.core.window import Window
Window.size = 360, 640
class Layout_(MDFloatLayout):
pass
kv = '''
#:import utils kivy.utils
#:import gch kivy.utils.get_color_from_hex
MDFloatLayout:
md_bg_color: 0, .6, 1, .5
ScrollView:
size: self.size
GridLayout:
id: card_container
size_hint_y: None
height: self.minimum_height
width: self.minimum_width
cols: 1
spacing: "20dp"
padding: "20dp"
'''
class MyCard(MDCard):
def __init__(self, title, text, **kwargs):
super(MyCard, self).__init__(**kwargs)
self.title = title
self.text = StringProperty()
self.padding = "8dp"
self.elevation = 40
self.size_hint = (1, None)
self.border_radius = 20
self.radius = [15]
self.orientation = "vertical"
class MainTest(MDApp):
def build(self):
self.theme_cls.primary_palette = "Blue"
return Builder.load_string(kv)
def on_start(self):
container = self.root.ids.card_container
for card in range(10):
container.add_widget(MyCard(title="My Card", text="Something about the card"))
if __name__ == '__main__':
MainTest().run()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|