如何将kivymd MDCheckBox添加到kv RecycleView,标签显示复选框代表什么?



我目前正在开发一个应用程序,您可以在其中使用Python Kivy和KivyMD存储计划并获取通知,但是我对MDCheckbox有问题。所有当前计划都应以以下格式显示在菜单窗口中:PlanText(由MDLabel表示(和IsDone(由MDCheckbox表示(。但是,当应用程序运行时,除了复选框外,什么都没有 -没有任何计划文本: 正在运行的应用程序的屏幕截图

我的一些 Python 代码:

class PlansToDisplay(RecycleView):
"""This class is used to display user's current plans"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
@property
def data(self):
# If a user has already planned something, this function returns a list
# of dicts containing plan texts. If not, it just returns an empty list.

# -> For the record, -plan- is a tuple represented in
# the following format: (PlanText, PlanPriority, IsDone)
if current_day in STORAGE.to_dict.keys():
return [{"text": str(plan[0])} for plan in STORAGE.to_dict[current_day]]
return []

我的一些KV代码:

<MyButton@GridLayout>:
cols: 2

# Is supposed to contain a plan text
MDLabel:
size_hint: .8, None

# Is meant for keeping track of whether the 
# user's finished the plan or not.
MDCheckbox:
size_hint: .2, None

<PlansToDisplay>:
viewclass: "MyButton"
grid: grid
RecycleGridLayout:
id: grid
orientation: 'vertical'
cols: 1
size_hint: 1, None
default_size: None, None
default_size_hint: 1, None
height: self.minimum_height

提前感谢!

我怀疑您需要在MyButton类中添加一个text属性,如下所示:

<MyButton@GridLayout>:
cols: 2
text: ''

# Is supposed to contain a plan text
MDLabel:
size_hint: .8, None
text: root.text

# Is meant for keeping track of whether the 
# user's finished the plan or not.
MDCheckbox:
size_hint: .2, None

您可能需要为MDCheckBox做类似的事情。

最新更新