python - 如何使用显示复选框代表什么的标签将 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
提前致谢!
解决方案
我怀疑您需要向您的班级添加一个text
属性,如下所示:MyButton
<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
.
推荐阅读
- ios - 在不增加图标大小的情况下增加可触摸区域
- node.js - 当我完成一个功能来查看已经添加的编队的详细信息时,我使用 Angular 2,没有显示任何内容
- angular - Angular:如何在 for 循环中使用服务?
- tensorflow - 带有 conda 的 TensorFlow-gpu:CUDA_HOME 在哪里指定?
- python - 如何使用 Dialogflow v2 的 Python 客户端发送文本响应?
- java - IntelliJ 找不到 LocalDate.of() 方法
- angular - Using *ngFor to loop over data fetched from server
- php - 为什么 PHP 数组中不存在 HTML 下拉列表的第一个条目
- php - 正则表达式不适用于空格
- java - Download file using REST API