469,085 Members | 1,017 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,085 developers. It's quick & easy.

How to do a callback from externally triggered event

I am using PIL to make images that I need to display in a sequence.
The image needs to change when a an event happens from a serial port.

I call the following function to display the image, but then the
application is waiting for an event. I need to return to the main
code which is sending commands to a serial port and waiting for data
to return then displaying the next chart.

def display(R,G,B):
img = Image.new('RGB',(1000,1000),(24,24,24))
draw = ImageDraw.Draw(img)
draw.rectangle((400,400,600,600), fill=(R,G,B))

root = Tkinter.Tk()
photo = ImageTk.PhotoImage(img)
label = Tkinter.Label(root, image=photo)
label.pack()
root.mainloop()
Here is the (very)rough program
#!/usr/local/bin/pythonw

# Import needed modules
import Tkinter, ImageTk
import Image, ImageDraw
import time, serial

def measure():
ser.write("M\n")
line = ser.readline()
print line,

def display(R,G,B):
img = Image.new('RGB',(1000,1000),(24,24,24))
draw = ImageDraw.Draw(img)
draw.rectangle((400,400,600,600), fill=(R,G,B))

root = Tkinter.Tk()
photo = ImageTk.PhotoImage(img)
label = Tkinter.Label(root, image=photo)
label.pack()
root.mainloop()
def setup_comm():
ser = serial.Serial('/dev/tty.KeySerial1')
ser.write("PR701\n")
time.sleep(.2)
ser.flushOutput()
line = ser.readline()
print line
# Program Starts here

setup_comm()
display(0, 255, 255)
measure()
display(255, 0, 255)
measure()
display(255, 255, 0)
measure()
Feb 17 '08 #1
0 810

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by ma740988 | last post: by
3 posts views Thread by Marten Van Keer | last post: by
2 posts views Thread by Marten Van Keer | last post: by
1 post views Thread by Abel Chan | last post: by
2 posts views Thread by Wizzard | last post: by
reply views Thread by skberen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.