我想实现两种加载弹出窗口:
第一个弹出窗口正常工作。但是,直到功能完成,第二个弹出窗口才会显示。我认为我在某个地方缺少Clock.schedule_once,但是我不确定确切在哪里以及如何实现它。
class BoxL(BoxLayout):
def __init__(self):
super(BoxL, self).__init__()
def next(self, dt):
if self.progress_bar.value>=100:
return False
self.progress_bar.value += 1
if self.progress_bar.value == 100:
self.popup.dismiss()
def next_manually(self, dt):
if self.progress_bar.value>=100:
return False
self.progress_bar.value = self.loadingValue
if self.progress_bar.value == 100:
self.popup.dismiss()
self.loadingValue = 0
def loading(self, *argv):
if len(argv) == 1:
loadingText = argv[0]
if len(argv) == 2:
loadingText = argv[0]
loadingTime = argv[1]
self.progress_bar = ProgressBar()
self.popup = Popup(title='[b]Loading: [/b]' + loadingText,
title_size = 20,
title_align = 'center',
auto_dismiss = False,
size_hint = (None, None),
size = (384, 160),
content = self.progress_bar)
if len(argv) == 2:
self.popup.bind(on_open=
Clock.schedule_interval(self.next, loadingTime/100))
if len(argv) == 1:
self.popup.bind(on_open=
Clock.schedule_interval(self.next_manually, 5/100))
self.progress_bar.value = 0
self.popup.open()
现在是实际调用弹出窗口的函数:
def test(self):
self.loading('Testload', 5)
def test2(self):
self.loading('TestLoad2')
time.sleep(1)
self.loadingValue = 10
time.sleep(1)
self.loadingValue = 30
time.sleep(1)
self.loadingValue = 35
time.sleep(1)
self.loadingValue = 50
time.sleep(1)
self.loadingValue = 60
time.sleep(1)
self.loadingValue = 90
time.sleep(1)
self.loadingValue = 100
答案 0 :(得分:0)
您没有显示如何调用test2()
,但是如果它在主线程上执行,那么它将在主线程上停止所有其他执行7秒钟(对{{1}的7次调用})。然后,当它完成时,主线程可以继续执行,并且sleep
的值将更新为ProgressBar
,当时的值为loadingValue
。我认为您需要将大多数100
方法放在另一个线程中。尝试这样的事情:
test2()