python - 如何使用 tkinter python 在控制台底部显示进度条
问题描述
我想始终在底部显示我的进度条,我的“for”循环包裹在 tqdm 周围,并且正在调用一些函数,该函数每次都需要将近 45 秒,并为某些代码打印成功和失败消息。我正确地获得了进度条,但是对于每个循环,例如如果我的“for”循环迭代 5 次,那么每次调用都会显示 5 个进度条。我的控制台看起来像这样 -
0%| | 0/4 [00:00<?, ?it/s]
Processing ---ASHISH KUMAR SINGH ---
ASHISH KUMAR SINGH is registered already
Failure --- ASHISH KUMAR SINGH --- due to Message: no such window: window was already closed
(Session info: chrome=86.0.4240.111)
25%|█████████████████████████ | 1/4 [00:16<00:49, 16.52s/it]
Processing ---ANJANI LAL ---
ANJANI LAL is registered already
Failure --- ANJANI LAL --- due to Message: no such window: window was already closed
(Session info: chrome=86.0.4240.111)
50%|██████████████████████████████████████████████████ | 2/4 [00:25<00:28, 14.19s/it]
Processing ---SORAV SAINI ---
SORAV SAINI is registered already
Failure --- SORAV SAINI --- due to Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=86.0.4240.111)
75%|███████████████████████████████████████████████████████████████████████████
我怎样才能更新底部的栏,例如我希望一个栏保留在底部并为每个循环动态更新这样->
Processing ---ANJANI LAL ---
ANJANI LAL is registered already
Failure --- ANJANI LAL --- due to Message: no such window: window was already closed
(Session info: chrome=86.0.4240.111)
Processing ---SORAV SAINI ---
SORAV SAINI is registered already
Failure --- SORAV SAINI --- due to Message: no such window: target window already closed
from unknown error: web view not found
(Session info: chrome=86.0.4240.111)
100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4
我希望这个栏保持在底部并动态更新我怎样才能做到这一点?谢谢
解决方案
使用 tqdm.write() 代替打印功能效果很好。现在我得到了正确的输出,因为我想成为感谢@acw1668
推荐阅读
- angular - Angular - 错误 NG8001:“app-landing-topnavbar”不是已知元素
- javascript - React js在中间用省略号截断文本
- python - 在 spaCy 中没有完全识别连词?
- android - 将 Android 应用程序连接到在线数据库的最佳(最安全)方式
- sharepoint - Confluence 作为 CMS
- javascript - 网络组件社区聚合物网络组件
- php - Apache PHP localhost 更改响应太慢
- flutter - agora.io颤振访问拒绝找到属性“net.dns1”
- php - ZipArchive 仅在 Windows 中无效
- r - 如何修改此代码块以重新编码数据框中的所有约 400 个变量,而不仅仅是一个?