[Tutor] Percent done bar
Alfred Milgrom
fredm@smartypantsco.com
Mon Nov 18 20:03:01 2002
At 11:16 AM 18/11/02 +0000, alan.gauld@bt.com wrote:
> > >is it possable to have a "percent-done" metre using
> > Tkinter??
>
>Try using a scroll bar widget.
>
>Alan G.
Just wanted to say I really enjoy reading this list - there's always
something interesting coming up, so I thought I would contribute something
back.
I think a neater effect for a percent bar is obtained by using a line
object on a small canvas, as in the following:
(Alan: you'll notice that the code for the app, GUI, etc, is lifted
directly from your tutorial)
from Tkinter import *
class ClearApp:
def __init__(self, parent=0):
self.mainWindow = Frame(parent)
self.percentbar = Canvas(self.mainWindow)
self.percentbar.config(height=10, width=100, bg='black')
self.percentbar.create_line(0, 6, 0, 6, fill='red', width = 3,
tag='bar')
self.percentbar.pack()
fOuter = Frame(self.mainWindow, border=1, relief="sunken")
fButtons = Frame(fOuter, border=1, relief="raised")
bDraw = Button(fButtons, text="Draw Bar",
width=8, height=1, command=self.drawBar)
bQuit = Button(fButtons, text="Quit",
width=8, height=1, command=self.mainWindow.quit)
bDraw.pack(side="left", padx=15, pady=1)
bQuit.pack(side="right", padx=15, pady=1)
fButtons.pack(fill=X)
fOuter.pack(fill=X)
self.mainWindow.pack()
self.mainWindow.master.title("Percent bar")
def drawBar(self):
global x
if x < 100 : x = x+10
app.percentbar.coords('bar', 0, 6, x, 6)
app = ClearApp()
x = 0
app.mainWindow.mainloop()