我是Kivy的新手,因此,在我的情况下,我试图从屏幕上清除现有数据,然后在其中添加一个新的小部件,但未清除屏幕数据。这是我的情况
main.kv
<AddressBook>:
name: 'addressbook'
ScrollView:
do_scroll_x: False
MDList:
id: ml
这是我的屏幕,这里我显示MDList中的数据列表
main.py
class AddressBook(Screen):
"""AddressBook Screen uses screen to show widgets of screens."""
def __init__(self, *args, **kwargs):
super(AddressBook, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method inbox accounts."""
sqlExecute("DELETE FROM addressbook WHERE label='' ")
data = sqlQuery("SELECT label, address from addressbook")
if data:
for item in data:
meny = TwoLineAvatarIconListItem(text=item[0], secondary_text=item[1], theme_text_color='Custom',text_color=NavigateApp().theme_cls.primary_color)
meny.add_widget(AvatarSampleWidget(source='./images/avatar.png'))
self.ids.ml.add_widget(meny)
else:
content = MDLabel(font_style='Body1',
theme_text_color='Primary',
text="No Contact Found yet...... ",
halign='center',
bold=True,
size_hint_y=None,
valign='top')
self.ids.ml.add_widget(content)
def refreshs(self):
self.ids.ml.clear_widgets()
uikivysignaler.py
class UIkivySignaler(Thread):
def run(self):
kivyuisignaler.acquire()
while state.shutdown == 0:
try:
state.kivyapp.obj_1.refreshs()
except Exception as e:
print(e)
在这里我从uikivysignaler.py文件中调用refreshs()方法,它正在运行良好的代码,但没有清除我尝试过的on_press事件的屏幕,在这种情况下,它正在清除屏幕,但是为什么不起作用当我通过类对象调用方法时。为什么清除并添加小部件在这种情况下不起作用?