MCPcopy Index your code
hub / github.com/python/cpython / ProgressBar

Class ProgressBar

Tools/unittestgui/unittestgui.py:433–463  ·  view source on GitHub ↗

A simple progress bar that shows a percentage progress in the given colour.

Source from the content-addressed store, hash-verified

431
432
433class ProgressBar(tk.Frame):
434 """A simple progress bar that shows a percentage progress in
435 the given colour."""
436
437 def __init__(self, *args, **kwargs):
438 tk.Frame.__init__(self, *args, **kwargs)
439 self.canvas = tk.Canvas(self, height='20', width='60',
440 background='white', borderwidth=3)
441 self.canvas.pack(fill=tk.X, expand=1)
442 self.rect = self.text = None
443 self.canvas.bind('<Configure>', self.paint)
444 self.setProgressFraction(0.0)
445
446 def setProgressFraction(self, fraction, color='blue'):
447 self.fraction = fraction
448 self.color = color
449 self.paint()
450 self.canvas.update_idletasks()
451
452 def paint(self, *args):
453 totalWidth = self.canvas.winfo_width()
454 width = int(self.fraction * float(totalWidth))
455 height = self.canvas.winfo_height()
456 if self.rect is not None: self.canvas.delete(self.rect)
457 if self.text is not None: self.canvas.delete(self.text)
458 self.rect = self.canvas.create_rectangle(0, 0, width, height,
459 fill=self.color)
460 percentString = "%3.0f%%" % (100.0 * self.fraction)
461 self.text = self.canvas.create_text(totalWidth/2, height/2,
462 anchor=tk.CENTER,
463 text=percentString)
464
465def main(initialTestName=""):
466 root = tk.Tk()

Callers 1

createWidgetsMethod · 0.85

Calls

no outgoing calls

Tested by 1

createWidgetsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…