- 生活中很多事情都會(huì)有反饋機(jī)制渔扎,比如考試完奕枢,成績(jī)就是對(duì)這段時(shí)間學(xué)習(xí)效果的反饋泉唁;玩游戲經(jīng)驗(yàn)值就是對(duì)你在游戲中投入精力的反饋等等倡蝙。那么對(duì)于程序來(lái)說(shuō)也需要反饋曹铃,比如安裝一個(gè)軟件,如果沒(méi)有進(jìn)度條总放,那么你一定會(huì)很抓狂。因?yàn)槟愀緹o(wú)法確認(rèn)程序是否在正常工作好爬,還是任務(wù)已經(jīng)被已系統(tǒng)掛起局雄。那么本文就簡(jiǎn)單的介紹幾種
python
常用到的反饋進(jìn)度條方式(包括GUI
進(jìn)度條)
本文首發(fā)于伊洛的個(gè)人博客:https://yiluotalk.com,歡迎關(guān)注并查看更多內(nèi)容4媾凇>娲睢!
1. 使用 Progress
- 安裝
(yiluo) ? ~ pip install progress
Collecting progress
Downloading https://files.pythonhosted.org/packages/38/ef/2e887b3d2b248916fc2121889ce68af8a16aaddbe82f9ae6533c24ff0d2b/progress-1.5.tar.gz
Installing collected packages: progress
Running setup.py install for progress ... done
Successfully installed progress-1.5
- 創(chuàng)建一個(gè)腳本僵蛛,寫(xiě)入以下代碼
# 伊洛Yiluo
# https://yiluotalk.com
import time
from progress.bar import IncrementalBar
bar_list = [1, 2, 3, 4, 5, 6, 7, 8]
bar = IncrementalBar('progress bar', max=len(bar_list))
if __name__ == '__main__':
for i in bar_list:
bar.next()
time.sleep(1)
bar.finish()
- 命令行運(yùn)行
(yiluo) ? AllDemo python demo.py
progress bar |████████████ | 3/8
2. 使用 Tqdm
- 安裝
pip install tqdm
Collecting tqdm
Downloading https://files.pythonhosted.org/packages/8c/c3/d049cf3fb31094ee045ec1ee29fffac218c91e82c8838c49ab4c3e52627b/tqdm-4.41.0-py2.py3-none-any.whl (56kB)
|████████████████████████████████| 61kB 239kB/s
Installing collected packages: tqdm
Successfully installed tqdm-4.41.0
- 寫(xiě)入以下代碼
# 伊洛Yiluo
# https://yiluotalk.com
import time
from tqdm import tqdm
_bar = [1, 2, 3, 4, 5, 6, 7, 8]
for item in tqdm(_bar):
time.sleep(1)
- 命令行運(yùn)行
(yiluo) ? AllDemo python demo.py
62%|█████████████████████████████████▊ | 5/8
3. 使用 Alive Progress
- 也是很常用的尚蝌,和之前例子相差不大,有興趣的可以看以下具體的使用文檔
Alive Progress 傳送門(mén)
4. 使用 Pysimplegui(GUI)
- 安裝
(yiluo) ? ~ pip install pysimplegui
Collecting pysimplegui
Downloading https://files.pythonhosted.org/packages/22/a8/ec06b5ce8997411c542dc0f65848a89b6f852b1b9c0fde8ace89aec6703e/PySimpleGUI-4.14.1-py3-none-any.whl (288kB)
|████████████████████████████████| 296kB 286kB/s
Installing collected packages: pysimplegui
Successfully installed pysimplegui-4.14.1
# 伊洛Yiluo
# https://yiluotalk.com
import PySimpleGUI as sg
import time
bar_list = [1, 2, 3, 4, 5, 6, 7, 8]
for i, item in enumerate(bar_list):
sg.one_line_progress_meter('我是進(jìn)度條!', i+1, len(bar_list), 'key')
time.sleep(1)
-
來(lái)看看GUI的效果
歡迎下方【戳一下】【點(diǎn)贊】
Author:伊洛Yiluo
愿你享受每一天充尉,Just Enjoy !