wxPython vs Tkinter for imaging front end GUI???
fredrik at pythonware.com
Tue Jun 3 14:12:19 CEST 2003
Leonard J. Reder wrote:
> I have a command line image feature recognition code and I want to put a
> quick python script on it to execute it and give it a GUI. I need to
> read in an image (JPEG), rescale the image on a canvas sort of display,
> place mouse over it to select some coordinate points. And then just do
> other stuff with buttons and entries. I am confortable with TK from
> using tcl but in Tk there is not an easy way to handle scaled images on
> the canvas. Does wxPython have this sort of functionality included?
> Has this sort of thing been done with Tkinter and PIL in Python.
yes, all the time.
here's a minimal example (run as "python script.py imagefile"):
from PIL import Image, ImageTk
from Tkinter import Tk, Canvas, Button
root = Tk()
maxsize = 200, 200
im = Image.open(sys.argv)
truesize = im.size
print "scale is", float(truesize) / im.size,
print "image pixels per screen pixel"
photo = ImageTk.PhotoImage(im)
canvas = Canvas(root, width=im.size, height=im.size, bd=0)
canvas.xview_moveto(0) # reset coordinate system
canvas.create_image(0, 0, image=photo, anchor="nw")
x = event.widget.canvasx(event.x)
y = event.widget.canvasy(event.y)
x = x * truesize / im.size
y = y * truesize / im.size
print "clicked at original image pixel", x, y
Button(root, text="done", command=root.quit).pack()
for more info, check the documentation for PIL's ImageTk
More information about the Python-list