Kivy:属性错误:'super'对象没有属性"__getattr__",具有不需要的行为



出现主要错误

第153行,在initself.ids.date_text.text=str(datetime.now((.strftime('%A%d%B%Y'((文件";kivy\properties.pyx";,第964行,在kivy.properties.ObsObservableDict.getattrAttributeError:"super"对象没有属性">getattr">

我想添加我找到的这段代码,但它不起作用。这是我的主要.py

task_list_dialog = None  # Here
# Add the below functions
def show_task_dialog(self):
if not self.task_list_dialog:
self.task_list_dialog = MDDialog(
title="Create Task",
type="custom",
content_cls=DialogContent(),
)
self.task_list_dialog.open()
# add this entire function
def on_start(self):
"""Load the saved tasks and add them to the MDList widget when the application starts"""
try:
completed_tasks, uncomplete_tasks = db.get_tasks()
if uncomplete_tasks != []:
for task in uncomplete_tasks:
add_task = ListItemWithCheckbox(pk=task[0], text=task[1], secondary_text=task[2])
self.root.ids.container.add_widget(add_task)
if completed_tasks != []:
for task in completed_tasks:
add_task = ListItemWithCheckbox(pk=task[0], text='[s]' + task[1] + '[/s]',
secondary_text=task[2])
add_task.ids.check.active = True
self.root.ids.container.add_widget(add_task)
except Exception as e:
print(e)
pass
def close_dialog(self, *args):
self.task_list_dialog.dismiss()
def add_task(self, task, task_date):
'''Add task to the list of tasks'''
# Add task to the db
created_task = db.create_task(task.text, task_date)  # Here
# return the created task details and create a list item
self.root.get_screen('tasks').ids.container.add_widget(
ListItemWithCheckbox(pk=created_task[0], text='[b]' + created_task[1] + '[/b]',
secondary_text=created_task[2]))  # Here
task.text = ''

类对话框内容(MDBoxLayout(:

def __init__(self, **kwargs):
super().__init__(**kwargs)
# set the date_text label to today's date when useer first opens dialog box
self.ids.date_text.text = str(datetime.now().strftime('%A %d %B %Y'))
def show_date_picker(self):
"""Opens the date picker"""
date_dialog = MDDatePicker()
date_dialog.bind(on_save=self.on_save)
date_dialog.open()
def on_save(self, instance, value, date_range):
"""This functions gets the date from the date picker and converts its it a
more friendly form then changes the date label on the dialog to that"""
date = value.strftime('%A %d %B %Y')
self.ids.date_text.text = str(date)

class ListItemWith复选框(TwoLineAvatarIconListItem(:'''自定义列表项'''

def __init__(self, pk=None, **kwargs):
super().__init__(**kwargs)
# state a pk which we shall use link the list items with the database primary keys
self.pk = pk
def mark(self, check, the_list_item):
'''mark the task as complete or incomplete'''
if check.active == True:
# add strikethrough to the text if the checkbox is active
the_list_item.text = '[s]' + the_list_item.text + '[/s]'
db.mark_task_as_complete(the_list_item.pk)  # here
else:
the_list_item.text = str(db.mark_task_as_incomplete(the_list_item.pk))  # Here
def delete_item(self, the_list_item):
'''Delete the task'''
self.parent.remove_widget(the_list_item)
db.delete_task(the_list_item.pk)  # Here

class Left复选框(ILeftBodyTouch,MDCheckbox(:"quot"自定义左容器"quot;

这是我的.kv文件

MDScreen:
name: "tasks"
BoxLayout:
orientation:'vertical'
MDBottomNavigation:
MDBottomNavigationItem:
name: 'screen 1'
icon: 'home-variant-outline'
MDLabel:
text: 'Goals in Progress'
font_name: 'Times'
font_size: '25sp'
pos_hint: {"center_x": 0.75, "center_y": .970}
MDIconButton:
icon: "square-edit-outline"
pos_hint: {"x": .869, "y": .001}
elevation: 18
DialogContent:
orientation: "vertical"
spacing: "10dp"
size_hint: 1, None
height: "130dp"
GridLayout:
rows: 1
MDTextField:
id: task_text
hint_text: "Add Task..."
pos_hint: {"center_y": .4}
max_text_length: 50
on_text_validate: (app.add_task(task_text, date_text.text), app.close_dialog())
MDIconButton:
icon: 'calendar'
on_release: root.show_date_picker()
padding: '10dp'
MDLabel:
spacing: '10dp'
id: date_text
BoxLayout:
orientation: 'horizontal'
MDRaisedButton:
text: "SAVE"
on_release: (app.add_task(task_text, date_text.text), app.close_dialog())
MDFlatButton:
text: 'CANCEL'
on_release: app.close_dialog()
ListItemWithCheckbox:
id: the_list_item
markup: True
LeftCheckbox:
id: check
on_release:
root.mark(check, the_list_item)
IconRightWidget:
icon: 'trash-can-outline'
theme_text_color: "Custom"
text_color: 1, 0, 0, 1
on_release:
root.delete_item(the_list_item)

当我通过注释函数来运行代码时,我也会有一些不必要的行为。

不必要的行为有人能帮我处理一下吗。非常感谢。

class DialogContent(MDBoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Clock.schedule_one(self.set_date_text)
def set_date_text(self., *args):
self.ids.date_text.text = str(datetime.now().strftime('%A %d %B %Y'))

最新更新