Need Help with Tkinter Plotting

timin at homeSPAMNOT.com timin at homeSPAMNOT.com
Wed Aug 30 21:45:51 EDT 2000


Hello,

I want to draw graphs with Tkinter.  I have this little script (below) that
draws a couple of nice graphs.  The problem is that it causes problems when I
close the window.  After the graphs are drawn the only way to close the window
is with the window close "X" in the upper right corner.  I added the
root.quit() function in order to terminate the program when the window is
closed, but it is not reliable.  Sometimes it freezes the DOS or IDLE window
that called up the plotting window.

What is the proper way to terminate a drawing when you are through looking at
it?
Can I add a close button to a canvas, or does this require a frame?  Can I use
a frame instead of a canvas to add a button and also to draw on?

I am using MS Win 98.

Thanks, your help is appeciated,

m
--------------------------------------------------------------------------------

# curve plotting demo:
from Tkinter import *

root=Tk()
root.protocol("WM_DELETE_WINDOW", root.quit())
canvas=Canvas(root,width=810,height=600)
canvas.pack()

offset = 5
dx = 40
xs = offset
xf = xs + dx
yf = ys = offset
zs = zf = 460

for i in range(1,21):
    canvas.create_line(xs, ys, xf, yf, width=2,fill="blue")
    canvas.create_line(xs, zs, xf, zf, width=2,fill="green")
    xs = xf
    ys = yf
    zs = zf
    xf = xf + dx
    yf = i*i + offset
    zf = 460 - i*i

root.mainloop()




More information about the Python-list mailing list