Fun with Tkinter & DISLIN?
Paul M
paul.m at yale.edu
Sun Dec 12 16:30:54 EST 1999
Greetings --
I've been playing around developing a object-oriented wrapper around
the DISLIN plotting library. For demo purposes I'm trying to write a
short Tkinter based interface which shows of some of the functionality
of my efforts.
I'm not very familiar with GUI programming, so I've been trying to
follow the lead of various demos included with the Python Source.
Stealing from an earlier exampled posted by Ionel Simionescu using the
wxPython toolkit, the following example does what I want it to - it
draws a scatter plot in a window, and correctly repaints and resizes.
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?
Thanks,
Paul
------------wxPython Version------------
from wxPython.wx import *
import pxDobject
import pxDplot
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 dislin_frame(wxFrame):
def __init__(self):
wxFrame.__init__(
self,
NULL, -1, "wxDisDemo",
wxDefaultPosition,
wxSize(600,600)
)
self.scatter = pxDplot.dScatter(x,y)
self.scatter.external_ID = self.GetHandle()
def OnPaint(self, event):
self.scatter.draw()
event.Skip()
class myApp(wxApp):
def OnInit(self):
dislin_frame().Show(TRUE)
return TRUE
if __name__ == '__main__':
app = myApp(0)
app.MainLoop()
-----Tkinter version------------------------
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):
def __init__(self, master):
self.master = master
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)
root.mainloop()
if __name__ == '__main__':
main()
More information about the Python-list
mailing list