在我的项目中,我使用KivyMD的MDSpinner
类显示小部件的加载状态。代码如下:
KV文件(相关部分)
MDSpinner:
id: spinner
size_hint: None, None
size: dp(46), dp(46)
pos_hint: { 'center_x': .5, 'center_y': .9 }
active: True if app.processing else False
我具有布尔属性处理和相应的on_processing函数,如下所示
class Mark2MarketApp(MDApp):
processing = BooleanProperty(defaultValue=False)
def __init__(self, **kwargs):
super().__init__(**kwargs)
start = time.time()
Builder.load_file("RootWidget.kv")
self.screen_manager = ScreenManager()
addMainScreen(self.screen_manager, self)
self.screen_manager.current = "Main"
self.current = "Main"
self.processing = False
self.manager_open = False
self.filePath = ""
self.symbol = []
self.qty = []
self.cost = []
self.side = []
Window.bind(on_keyboard=self.events)
self.file_manager = MDFileManager(
exit_manager=self.exit_manager,
select_path=self.select_path,
)
self.file_manager.ext = ['.csv', '.CSV', '.xlsx', '.XLSX']
self.popup = self.get_popup()
self.no_data_popup = self.no_data_popup()
end = time.time()
print('elapsed time for startup is %d seconds ' % (end - start))
def on_processing(self, instance, value):
print('instance, value', instance, value)
我在代码之前和之后设置处理变量,如下所示
def gain_loss(self):
self.processing = True
try:
gl = self.screen_manager.get_screen('GainLoss')
gl.add_widgets()
except ScreenManagerException:
gl = GainLossScreen(self.screen_manager, name='GainLoss')
self.screen_manager.add_widget(gl)
gl.add_widgets()
if len(tryout.product_dict) == 0:
self.no_data_popup.open()
else:
self.screen_manager.current = 'GainLoss'
self.processing = False
但是,微调器没有被激活。我调试了MDSpinner源代码,并在处理设置为True时确实调用了activation.start方法,在处理设置为false时停止了动画。但是微调框不会旋转!。
有趣的是,如果我在最后一行注释掉self.processing = False,则微调框开始旋转。
预先感谢