Kivy中的进度条无法使用循环更新 [英] Progress bar in kivy can't update using loop

查看:56
本文介绍了Kivy中的进度条无法使用循环更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯托盘可以在kivy中创建进度条,我可以用它来构建应用程序,但是当我运行一个函数(循环)时它不能被覆盖,请问我该怎么做?

im traying to do a progress bar in kivy, i can build the app with it but it can't be udpated when i run a function (loop) how can i do this please ?

这是我的代码: 导入库:

here is my code : import libraries :

from kivy.app import App

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout

from kivy.uix.label import Label
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivy.clock import Clock
from kivy.logger import Logger
from kivy.uix.progressbar import ProgressBar

我的建造者:

Builder.load_string("""
<RootWidget>:
    pb : pb
    some code here
        ActionView:       
            ActionPrevious:
                with_previous: False 
                ActionButton:
                    text: 'Run analysis'
                    color: 29/255, 185/255, 84/255, 1
                    on_release: root.clicked()
    BoxLayout:
        ProgressBar:
            id : pb
            min :0
            max :1
            pos_hint: {'x': .1}
            size_hint_x :.8
            size_hint_y :.5
            value: 0
        """)

其他带有我的update_bar函数的代码:

other code with my update_bar function:

class Myapp(BoxLayout):

    pb = ProgressBar()
    box = ObjectProperty()

    def __init__(self, *args, **kwargs):
        super(Myapp, self).__init__(*args, **kwargs)

    def update_bar(self,dt=None):
         self.ids.pb.value = self.ids.pb.value

这是问题所在:进度条不会在每次迭代时更新,但会使用最后一个值(对于i = 9999)

here is the problem : the progress bar is not updated each iteration, but it take the last value (for i = 9999)

     def clicked(self):
        for i in range(10000) :
            self.ids.pb.value =  i/10000 
            Clock.schedule_interval(self.update_bar,0.5)
            self.update_bar()

构建我的应用程序:

class EventScreen(App,Myapp):
    def on_stop(self):
        Logger.critical("Good bye")
    def build(self):
        return Myapp()
if __name__ == "__main__":
    EventScreen().run()

先谢谢您

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆