当按下保存按钮时,我想显示“数据已保存”几秒钟。似乎他正在调用这两个函数,但是我的标签文本没有像“ .send_button_answer.text ='已保存数据'”那样更新。最后,标签仅显示点->'。'。
我的kv文件:
Button:
id: send_button
text: 'Save data'
on_press: app.set_variable_to_db("vendor", user_name.text)
on_press: root.configuration_save_button_pressed()
Label:
Label:
id: send_button_answer
text: "..."
我的Python代码:
class TestWidget(TabbedPanel):
def configuration_save_button_pressed(self):
self.ids.send_button_answer.text = 'Data saved'
self.configuration_save_button_pressed_2()
def configuration_save_button_pressed_2(self):
time.sleep(2)
self.ids.send_button_answer.text = '.'
[time.sleep
]照样执行:程序不执行任何操作,包括更新gui。
解决方案是使用kivy的时钟而不是阻塞它。改为使用Clock.schedule_once(self.configuration_save_button_pressed_2, 2)
,并使该方法使用单个参数(它可以忽略该参数,但时钟计划仍将传递它)。