473,383 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 907

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ma740988 | last post by:
// file sltest.h #ifndef SLTEST_H #define SLTEST_H class CallbackBase // herb shutters gotW source .. { public: virtual void operator()() const { }; virtual ~CallbackBase() = 0; };
3
by: Marten Van Keer | last post by:
Hello; I have an application that waits for TCP packets to arrive on a network stream. A callback function(using an asynccallback delegate) is implemented to tell the application some packets...
2
by: Marten Van Keer | last post by:
Hi; I have two applications A and B *** Application B listens on a network stream with a callback function:
1
by: Abel Chan | last post by:
Hi there, I was trying to write a simple NT services using .NET 2.0 and fileSystemWatcher control. The goal is to poll documents from a watch directory and ftp them to a remote web site. I...
2
by: Wizzard | last post by:
I have a repeater with and imagebutton on a page useing VS2005 ASP.Net 2.0 <asp:Repeater ID="Repeater1" runat="server" > <ItemTemplate> <div> <asp:ImageButton ImageUrl="button.gif"...
0
by: skberen | last post by:
Issue: We have a web user control on a web page (aspx) that uses the new ASP.Net 2 feature Client Callback. The web user control is using a CheckBoxList control and button control to allow the...
5
by: jason.neo | last post by:
Hi all experts, I am going nuts with this Invalid postback or callback argument thingy with .Net 2.0 I am building a file attachment module which relays on a Datatable stored in session (yeah...
1
by: FordPrefect | last post by:
I am using a 3rd party dll (not COM). One of the dll functions requires a callback function. I have used either DllImport or Declare to properly (I think) declare the function. The function...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.