【发布时间】:2020-07-07 15:52:14
【问题描述】:
我想实现两种加载弹窗:
- 以预定义的持续时间调用弹出窗口
- 从其他功能更新弹出窗口
第一个弹出窗口正常工作。但是,在函数完成之前,第二个弹出窗口不会显示。我想我在某个地方错过了 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
【问题讨论】:
标签: python popup kivy progress-bar clock