In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Python to add progress bar", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use Python to add progress bar" bar!
Undefined
Four common Python progress bar libraries are described below:
Progress
The first Python library to be introduced is Progress.
You only need to define the number of iterations, the type of progress bar, and inform the progress bar at each iteration.
Import timefrom progress.bar import IncrementalBarmylist = [1 Countdown', max 2 3 time.sleep 4 5 6 7 8] bar = IncrementalBar ('Countdown', max = len (mylist)) for item in mylist: bar.next () time.sleep (1) bar.finish ()
The effect of the progress bar implemented by Progress is as follows:
If you don't like the format of the progress bar, you can also choose from the following formats:
Related documentation: https://pypi.org/project/progress/1.5/
Tqdm
Let's take a look at the tqdm library.
Similar to the libraries you've seen before, these two lines of code are also very similar, with a slight difference in setup:
Import timefrom tqdm import tqdmmylist = [1 mylist 2 3 4 4 5 6 7 8] for i in tqdm (mylist): time.sleep (1)
The effect of the progress bar implemented by tqdm is as follows:
This progress bar also provides several options.
Related documentation: https://tqdm.github.io/
Alive Progress
As the name implies, this library can make the progress bar lively, and it has some more animation effects than the progress bar we have seen before.
Similar from a code point of view:
From alive_progress import alive_barimport timemylist = [1 len 2 (mylist)) as bar: for i in mylist: bar () time.sleep (1)
The appearance of the progress bar is similar to that expected:
This progress bar has some distinctive features that will be interesting to use. For more information, please see the project: https://github.com/rsalmei/alive-progress.
PySimpleGUI
(1) get the graphical progress bar with PySimpleGUI
We can add a simple line of code to get a graphical progress bar in the command line script.
To achieve the above, the code we need is:
Import PySimpleGUI as sgimport timemylist = [1 len 2, 3 key-' 4 5, 6 7, 8] for I, item in enumerate (mylist): sg.one_line_progress_meter ('This is my progress meterials, item1, len (mylist),'-key-') time.sleep (1)
(2) Progress bar in PySimpleGUI application
The project author has previously discussed "how to start Python UI quickly and then use UI to create a comparison tool" on GitHub. In this project, the author also discusses how to integrate the progress bar.
The code is as follows:
Import PySimpleGUI as sgimport timemylist = [sg.ProgressBar (len (mylist), orientation='h', size= (51,10), key='progressbar')]] outputwin = [[sg.Output (size= (78)]] layout= [[sg.Frame ('Progress',layout= progressbar)], [sg.Frame (' Output', layout= outputwin)], [sg.Submit ('Start'), sg.Cancel ()] window = sg.Window (' Custom Progress Meter') Layout) progress_bar = window ['progressbar'] while True: event, values = window.read (timeout=10) if event = =' Cancel' or event is None: break elif event = = 'Start': for iStart': for item in enumerate (mylist): print (item) time.sleep (1) progress_bar.UpdateBar (I + 1) window.close () Thank you for reading The above is the content of "how to use Python to add progress bar". After the study of this article, I believe you have a deeper understanding of how to use Python to add progress bar, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.