Fun with Tkinter & DISLIN?

Fredrik Lundh fredrik at pythonware.com
Mon Dec 13 05:24:55 EST 1999


Paul M <paul.m at yale.edu> wrote:
> The second version using Tkinter draws the plot correctly, but
> immediately redraws over it with the standard grey window.  If I
> resize the window I see that the plot is being redrawn at a new size
> but then immediately gets written over again.
> 
> Can anyone point me in the right direction?

change "Canvas" to "Frame", and set the background
colour to an empty string (this prevents Tkinter from
drawing its own contents into the widget).

> from Tkinter import *
> from pxDplot import *
> 
> x = [61, 37, 65, 69, 54, 93, 87, 89, 100, 90, 97]
> y = [14, 17, 24, 25, 27, 33, 34, 37, 40, 41, 42]
> 
> class Demo(Canvas):

class Demo(Frame):

>     def __init__(self, master):

umm. python doesn't call base-class constructors
by itself, so I'm not sure how this could work at all.

anyway, to fix this, change this line:

>         self.master = master

to:

    Frame.__init__(self, master, bg="")

>         self.scatter = dScatter(x,y)
>         self.scatter.external_ID = self.master.winfo_id()
>         self.scatter.draw()
>         self.master.bind('<Configure>', self.reconfigure)
> 
>     def reconfigure(self, event):
>         self.scatter.draw()
> 
> def main():
>     root = Tk()
>     demo = Demo(root)
>     root.protocol('WM_DELETE_WINDOW', root.quit)

make that "root.destroy", not "root.quit".  not that it
matters much in this little program...

>     root.mainloop()
> 
> if __name__ == '__main__':
>     main()

hope this helps!

</F>





More information about the Python-list mailing list