Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

displaying an Image using PIL w/o Image.show

5 views
Skip to first unread message

Tech

unread,
Nov 19, 2001, 10:29:58 PM11/19/01
to
How do to show an Image in PIL without calling the Image.Show()
Method? I tried to use Image.Show() but I don't have some lib that I
need. Anyway the online docs seemed to suggest the there may be a
better way but did not say what it was.

Thanks In Advance,
Tech

Quick Dry

unread,
Nov 19, 2001, 11:24:10 PM11/19/01
to

"Tech" <vze2...@verizon.net> wrote in message
news:3sjjvt0c8rnq3iuht...@4ax.com...

you could display the image on a Canvas, thus showing it all via Python

heres a quick hack I used to show an updated image from a webcam, its
probably got all sorts of bad style, but shows an image on a canvas, and
updates it every so often

------------ code starts here ------------

from Tkinter import *
import Image, ImageTk
import webcam # has methods to get images from a webcam

Width, Height = 320, 240

ADDRESS="127.0.0.1"
PORT="8081"
REFRESH=500


class Camera(Frame):
def __init__(self, parent=None, title='eHome', address=ADDRESS,
port=PORT, msecs=1000, **args):
Frame.__init__(self, parent, args)
self.title=title
self.address=address
self.port=port
self.makeWidgets()
self.pack(expand=YES, fill=BOTH)
self.width=WIDTH
self.height=HEIGHT
self.image_store = None
self.msecs = msecs
self.confirmQuit = 0
self.drawn = None
self.fit = 1

def makeWidgets(self):
self.canvas = Canvas(self, bg='white', height=Height, width=Width)
self.canvas.pack(side=LEFT, fill=BOTH, expand=YES)
self.onoff = Button(self, text='Start', command=self.onStart)
self.onoff.pack(fill=X)
Button(self, text='Quit', command=self.onQuit).pack(fill=X)


def onStart(self):
self.loop = 1
self.onoff.config(text='Stop', command=self.onStop)
self.canvas.config(height=self.height, width=self.width)
self.onTimer()

def onStop(self):
self.loop = 0
self.onoff.config(text='Start', command=self.onStart)

def onQuit(self):
self.onStop()
self.update()
if not self.confirmQuit:
self.quit()
else:
if askyesno(self.title, 'Really quit now?'):
self.quit()

def onTimer(self):
if self.loop:
self.drawNext()
self.after(self.msecs, self.onTimer)

def drawNext(self):
if self.drawn:
self.canvas.delete(self.drawn)
name = "campic"
img = self.getCamPic()
img1=ImageTk.PhotoImage(image=img)
self.drawn = self.canvas.create_image(2, 2, image=img1, anchor=NW)
self.image = name, img1
self.canvas.update()

def getCamPic(self):
img=ImageTk.PhotoImage(data=webcam.read(self.address+":"+self.port))
return img


if __name__ == '__main__':
root = Tk()
root.title('CamView 1.0')
Label(root, text="Cameras").pack()
Camera(root, bd=3, address=ADDRESS, port=PORT, msecs=REFRESH,
relief=SUNKEN).pack()
root.mainloop()

Jeff Shannon

unread,
Nov 20, 2001, 3:41:42 PM11/20/01
to

Tech wrote:

What lib does it say that you need? What platform are you using? What
GUI toolkit are you using, or intending to use? (You can't display an
image without a window to display it in.)

Jeff Shannon
Technician/Programmer
Credit International


0 new messages