1 ImportSYS2 Import Time3total_size=102124Recv_size=05 defProgress (percent,width=50):6 ifPercent > 1:#if the percentage is greater than 1, take 1.7Percent=18Show_str= ('[%%-%ds]'%width)% (int (percent*width) *'#')9 #altogether 50 #,%d unsigned integers,-representing left-aligned, non-newline output, two% representing a pure%, corresponding to the back of S, followed by the number of control # numbersTen #print (SHOW_STR) #[###############] show_str, output once each time One Print('\r%s%s%%'% (Show_str,int (percent*100)), end="', file=sys.stdout,flush=True) A #\ r represents the beginning of the start of the meaning, \ n for the meaning of the line, Fiel representative output to where, flush=true represents no delay, immediately refreshed. The second%s is a percentage - whileRecv_size < total_size:#when the received size is less than the total large hour -Time.sleep (0.2)#1024x768 therecv_size+=1024#every time you receive the 1024x768 -Percent=recv_size/total_size#Calculate percent 0.10027418723070897 -Progress (PERCENT,WIDTH=30)#Call the progress bar function and pass the percentages in
1 Results: 2 [##############################] 100%
Python Print progress bar