本文介绍了python中的进度条curses的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个进度条,它会在从另一个函数获取百分比后自行更新,但是我在让它像这样############ 跟踪时遇到了问题.相反,它只是将#"向右移动,直到达到 100%.下面是我的代码.之所以这样,是因为我需要百分比来自外部,以便代码可以重用.请帮帮我.
I have created a progress bar which updates itself after getting a percentage from another function but I'm having issues getting it to trail like this ############. Instead, it just move the '#' to the right until 100% is reached. Below is my code. The reason why it's this way is because I need the percentage to come externally so that the code can be reusable. please help me.
import curses
import time
curses.initscr()
def percentage():
loading = 0
while loading < 100:
loading += 1
time.sleep(0.03)
update_progress(loading)
def update_progress(progress):
win = curses.newwin(3, 32, 3, 30)
win.border(0)
rangex = (30 / float(100)) * progress
pos = int(rangex)
display = '#'
if pos != 0:
win.addstr(1, pos, "{}".format(display))
win.refresh()
percentage()
推荐答案
你可以切换pos
来乘以display #
:
if pos != 0:
win.addstr(1, 1, "{}".format(display*pos))
win.refresh()
这篇关于python中的进度条curses的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!