Production of Python's progress bar

Source: Internet
Author: User

1 ImportSys,time2 #Import Module3 4  forIinchRange (50):5 #the length of the progress bar6Sys.stdout.write ("#")7 #the contents of the progress bar, it is important to note that Pycharm may not show the method of write8 Sys.stdout.flush ()9 #Refresh CacheTenTime.sleep (0.5) One #time interval, like the Shell's sleep.

Or

ImportSYSclassProgressBar (object):def __init__(Self, finalcount, block_char='.'): Self.finalcount=Finalcount Self.blockcount=0 Self.block=Block_char self.f=Sys.stdoutif  notSelf.finalcount:returnSelf.f.write ('\ n------------------% Progress-------------------1\n') Self.f.write ('1 2 3 4 5 6 7 8 9 0\n') Self.f.write ('----0----0----0----0----0----0----0----0----0----0\n')     defProgress (self, count): Count=min (count, Self.finalcount)ifSelf.finalcount:percentcomplete= Int (Round (100.0 * Count/self.finalcount))ifPercentComplete < 1: PercentComplete= 1Else: PercentComplete= 100Blockcount= Int (PercentComplete//2)        ifBlockcount <=Self.blockcount:return         forIinchRange (Self.blockcount, Blockcount): Self.f.write (Self.block) Self.f.flush () Self.blockcount =BlockcountifPercentComplete = = 100: Self.f.write ("\ n") if __name__=="__main__":     fromTimeImportSleep PB= ProgressBar (8,"*")     forCountinchRange (1, 9): pb.progress (count) sleep (0.2) PB= ProgressBar (100) pb.progress (20) Sleep (0.3) pb.progress (47) Sleep (0.3) pb.progress (90) Sleep (0.3) pb.progress (100)    Print "Testing 1:"PB= ProgressBar (1) pb.progress (1)

Or:

#-*-coding:utf-8-*-ImportSys, timeclassshowprocess ():"""The class that displays the progress of the process calls the class-related function to enable the display of processing progress"""I= 0#Current Processing ProgressMax_steps = 0#total number of processes requiredMax_arrow = 50#the length of the progress bar    #initialization function, you need to know the total number of processing times    def __init__(self, max_steps): Self.max_steps=max_steps self.i=0#Display the function, according to the current processing progress I show progress    #effect is [>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>]100.00%     defShow_process (Self, i=None):ifI is  notnone:self.i=IElse: self.i+ = 1Num_arrow= Int (SELF.I * self.max_arrow/self.max_steps)#calculation shows how many ' > 'Num_line = Self.max_arrow-num_arrow#calculation shows how many '-'Percent = SELF.I * 100.0/self.max_steps#Calculate completion progress, formatted as xx.xx%Process_bar ='['+'>'* Num_arrow +'-'* Num_line +']'                      +'%.2f'% percent +'%'+'\ r' #string with output, ' \ r ' means no line break back to the leftSys.stdout.write (Process_bar)#These two sentences print characters to the terminalSys.stdout.flush ()defClose (self, words=' Done'):        Print "'        Printwords self.i=0if __name__=='__main__': Max_steps= 100Process_bar=showprocess (max_steps) forIinchRange (Max_steps + 1): Process_bar.show_process () time.sleep (0.05) Process_bar.close ()

Or:

 fromTkinterImport*defResize (ev=None): Label.config (Font='Helvetica-%d Bold'%Scale.get ()) Top=Tk () top.geometry () label= Label (top, Text ='Hello world!', Font ='Helvetica-12 Bold') Label.pack (fill=y,expand=1) Scale= Scale (top, from_=10, to=40, Orient=horizontal, command=resize) scale.set (12) Scale.pack (fill=x, expand=1) Quit= Button (Top, text="QUIT", Command=top.quit, activeforeground=' White', activebackground='Red') Quit.pack () Mainloop ()

Production of Python's progress bar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.