[Tutor] To Arc (PIL) or Not to Arc (Tkinter)
Kent Johnson
kent37 at tds.net
Wed Jan 28 15:15:42 CET 2009
On Wed, Jan 28, 2009 at 8:25 AM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> I've been playing with PIL and Tkinter a bit, and see that PIL does not have
> any facility to view the image file I draw on. I open a file from my folder
> with a py program as an Image. The only way, without using some other
> module, is to save the changed file, then display it with a paint or photo
> program. Is that correct, or did I miss something in PIL?
The ImageTk module integrates PIL with Tkinter:
http://effbot.org/imagingbook/imagetk.htm
Here is a simple image viewer library, just call showImage() with your
loaded Image object:
# an image viewer
import ImageTk
from Tkinter import Tk, Label
class UI(Label):
def __init__(self, master, im):
if im.mode == "1":
# bitmap image
self.image = ImageTk.BitmapImage(im, foreground="white")
Label.__init__(self, master, image=self.image, bg="black", bd=0)
else:
# photo image
self.image = ImageTk.PhotoImage(im)
Label.__init__(self, master, image=self.image, bd=0)
def showImage(im):
root = Tk()
UI(root, im).pack()
root.mainloop()
Kent
More information about the Tutor
mailing list