Progress bars are popular when trying to show how much of a job has been completed. In my case, it was encrypting and decrypting files. A GUI interface was written, but something was lacking. How was the user of the program supposed to know if the program was doing its job? A progress bar seemed like a good answer, so a simple GUI progress bar was written using Tkinter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import Tkinter
class PB:
def settitle(self, title):
self.__root.title(title)
# Create Progress Bar
def __init__(self, width, height):
#self.__root = Tkinter.Toplevel()
self.__root = Tkinter.Tk() #updated by Petr
self.__root.resizable(False, False)
self.__root.title('Wait please...')
self.__canvas = Tkinter.Canvas(self.__root, width=width, height=height)
self.__canvas.grid()
self.__width = width
self.__height = height
# Open Progress Bar
def open(self):
self.__root.deiconify()
self.__root.focus_set()
#self.__root.update()
# Close Progress Bar
def close(self):
self.__root.withdraw()
# Update Progress Bar
def update(self, ratio):
self.__canvas.delete(Tkinter.ALL)
self.__canvas.create_rectangle(0, 0, self.__width * ratio, \
self.__height, fill='blue')
self.__root.update()
self.__root.focus_set()
|
You will need to catch errors when working with this class. The window can still be closed.