【问题标题】:How to show progress bar at bottom of console using tkinter python如何使用 tkinter python 在控制台底部显示进度条
【发布时间】:2020-11-01 11:18:52
【问题描述】:

我想始终在底部显示我的进度条,我的“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()而不是print()来输出其他消息。
  • 哇,@acw1668 这正是我想要的。非常感谢你,它工作得很好❤️❤️

标签: python tkinter cmd


【解决方案1】:

使用 tqdm.write() 代替打印函数效果很好。现在我得到了我想要的正确输出 感谢@acw1668

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 2022-01-10
    • 2016-06-28
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多