(Continuous) strip chart recorders with Tkinter/PIL
Chris WRIGHT
caw at cs.mu.OZ.AU
Sun Mar 26 21:11:15 EST 2000
I need to produce "strip chart" type screen output for various
physiological parameters. I'm currently using Tkinter with a Canvas, a
PhotoImage and the put method on the Image and calling update() to
redicplay the canvas. This is OK, but I'd like to make it a bit faster.
I'm not sure that using PIL will help...The putpixel method is certainly
quick, but the re-draw doesn't happen when I call update...
I'd be grateful for help and advice as to how to speed this process up
Sample code: (modified from "plot single pixel" thread)
from Tkinter import *
class App:
def __init__(self, master):
self.frame = frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red",command=frame.quit)
self.button.pack(side=LEFT)
self.test_B = Button(frame, text="Test", command=self.test)
self.test_B.pack(side=LEFT)
self.img = PhotoImage(height=100, width=100)
self.canvas = Canvas(frame, width=100, height=100)
self.canvas.create_image(0, 0, anchor=NW, image=self.img)
self.canvas.pack()
def test(self):
import time
max_x = max_y = 100
start = time.time()
start_cpu = time.clock()
m = self.frame.master
for x in range(max_x):
for y in range(max_y):
self.img.put("black", (x,y))
m.update() # UPDATE THE CANVAS
elapsed = time.time() - start
elapsed_cpu = time.clock() - start_cpu
print "done -- it took us: "
print elapsed
print elapsed_cpu
root = Tk()
app = App(root)
root.mainloop()
Dr Chris Wright
Deputy Director, Intensive Care Unit
Monash Medical Centre,
Clayton 3168 VIC
More information about the Python-list
mailing list