你可以在
tqdm
中通过在构造函数中指定一个
total
参数来使用手动控制。逐字逐句地从
手册
:
with tqdm(total=100) as pbar:
for i in range(10):
sleep(0.1)
pbar.update(10)
To 手册ly control the tqdm
without the context manager (aka with
statement), you will need to close the progress bar after you are done using it. Here is another example from the 手册:
pbar = tqdm(total=100)
for i in range(10):
sleep(0.1)
pbar.update(10)
pbar.close()
为了使其发挥作用,你需要知道预期运行的总数量。在你的代码中,它可以是这样的
pbar = tqdm(total = runs+1)
while currentData[0] <= runs:
### ROLLING THE DICES PROCESS ###
dices = twinDiceRoll()
currentData[1] += dices[2] # Updating the current tile
### SURPASSING THE NUMBER OF TILES ONBOARD ###
if currentData[1] > 37: # If more than a table turn is achieved,
currentData[0] += 1 # One more turn is registered
currentData[1] -= 38 # Update the tile to one coresponding to a board tile.
pbar.update(1)
else:
pbar.close()
然而,这段代码并不完美:考虑到如果currentData[1]
总是小于37 -- 进度条会直接停止而不更新。如果你试图在else:...
部分更新它,你可能会违反total
的上界。这只是一个开始 :)