PythonProgressBar(PyPi)-显示随update()更改的自定义文本

PythonProgressBar(PyPi)-显示随update()更改的自定义文本,python,progress-bar,Python,Progress Bar,嘿,我正在使用pypi的progressbar包,我非常喜欢它。我的问题是,到目前为止,我还没有找到显示自定义文本的方法。我的意思是,当我调用pbar.update() 例如,如果我递归地扫描计算机中的文件,我希望进度条更改为当前文件 widgets = [CustomText(), ' ', Percentage(), ' ', Bar('/'), ' ', RotatingMarker()] pbar = ProgressBar(widgets=widgets, maxval=1000) p

嘿,我正在使用pypi的progressbar包,我非常喜欢它。我的问题是,到目前为止,我还没有找到显示自定义文本的方法。我的意思是,当我调用
pbar.update()

例如,如果我递归地扫描计算机中的文件,我希望进度条更改为当前文件

widgets = [CustomText(), ' ', Percentage(), ' ', Bar('/'), ' ', RotatingMarker()]
pbar = ProgressBar(widgets=widgets, maxval=1000)
pbar.start()

pbar.update(0, "custom_string")
这样的事情对我来说最合适。但由于update函数只接受一个数字,我不知道如何在不改变进度条库本身的情况下实现类似的功能


提前感谢

我尝试在
FormatLabel
小部件中使用
update
方法来更改标签的内容,但对我无效。但是,用一个全新的对象替换
FormatLabel
,对我来说很有效:

from progressbar import *
import time

widgets = [FormatLabel(''), ' ', Percentage(), ' ', Bar('/'), ' ', RotatingMarker()]
progressbar = ProgressBar(widgets=widgets, maxval=10)
progressbar.start()
for i in range(0, 11):
    widgets[0] = FormatLabel('<filename-{0}>'.format(i))
    progressbar.update(i)
    time.sleep(.5)
progressbar.finish()
从progressbar导入*
导入时间
widgets=[FormatLabel(“”),“”,Percentage(),“”,Bar(“/”),“”,RotatingMarker()]
progressbar=progressbar(小部件=小部件,maxval=10)
progressbar.start()
对于范围(0,11)内的i:
widgets[0]=FormatLabel(“”.format(i))
progressbar.update(一)
时间。睡眠(.5)
progressbar.finish()

我试图在
FormatLabel
小部件中使用
update
方法来更改标签的内容,但它对我无效。但是,用一个全新的对象替换
FormatLabel
,对我来说很有效:

from progressbar import *
import time

widgets = [FormatLabel(''), ' ', Percentage(), ' ', Bar('/'), ' ', RotatingMarker()]
progressbar = ProgressBar(widgets=widgets, maxval=10)
progressbar.start()
for i in range(0, 11):
    widgets[0] = FormatLabel('<filename-{0}>'.format(i))
    progressbar.update(i)
    time.sleep(.5)
progressbar.finish()
从progressbar导入*
导入时间
widgets=[FormatLabel(“”),“”,Percentage(),“”,Bar(“/”),“”,RotatingMarker()]
progressbar=progressbar(小部件=小部件,maxval=10)
progressbar.start()
对于范围(0,11)内的i:
widgets[0]=FormatLabel(“”.format(i))
progressbar.update(一)
时间。睡眠(.5)
progressbar.finish()

非常有用,非常感谢,我确实查看了format label,但没有意识到每次更新时进度条都会重新检查小部件,再次感谢如果应用到末尾,请确保更新term_width以包括自定义文本的长度:bar.term_width=50+len(formatLabel)非常有用,非常感谢,我确实查看了format label,但不知道进度条每次更新时都会重新检查小部件,再次感谢。如果应用到末尾,请确保更新term_width以包含自定义文本的长度:bar.term_width=50+len(formatLabel)