首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Urwid ProgessBar未正确更新

Urwid ProgessBar未正确更新
EN

Stack Overflow用户
提问于 2014-03-26 01:02:21
回答 1查看 796关注 0票数 1

我正在尝试使用urwid库,到目前为止,它非常棒。但是我不能让Progressbar工作。我写了一个简单的测试程序,如下所示:

代码语言:javascript
复制
import os
import urwid

    # a function that takes some times to complete
def dosomething(steps, bar):
    bar.done = steps
    for i in range(steps + 1):
        bar.set_completion(i)
        os.system('sleep 0.2')

    # make a button to start
task_btn = urwid.Button(u'Task')
    # progressbar object
pbar = urwid.ProgressBar('pg normal', 'pg complete')

    # function called when the task button is clicked
def on_task_clicked(button):
    dosomething(10, pbar)

    # setup signal handler for the button
urwid.connect_signal(task_btn, 'click', on_task_clicked)

    """
     create the interface and the mainloop.
     filler objects are our friend to prevent unpacking errors :D
   """

loop = urwid.MainLoop(urwid.Pile([urwid.Filler(task_btn), urwid.Filler(pbar)]))
loop.run()

如果我启动它,进度条应该是0%。然后我按下按钮,几秒钟后进度条显示100%。但我错过了0%到100%之间的步骤。他们就是不肯露面。

另外,对渲染函数的额外调用也不会起作用。

我也尝试过这样的东西:

代码语言:javascript
复制
def on_task_clicked(button):
    pbar.set_completion(pbar.current+1)

这个可以很好的工作。看起来进度条对被循环调用并不满意。这看起来很奇怪?!有人有什么想法来解决这个问题吗?

提前感谢:)

PS: INFO: urwid 1.2.0在python 2.6.6、2.7、3.3上测试都是一样的

EN

回答 1

Stack Overflow用户

发布于 2015-03-27 06:59:50

这可能是因为没有调用主循环的draw_screen方法(它通常在循环进入空闲状态时自动调用)。

在for循环中添加loop.draw_screen()

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22641529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档