Help with PIL
John Michelsen
john.michelsen at gte.net
Thu May 27 11:38:52 EDT 1999
> I've just installed the PIL library on my win98 machine. I
>can open a file and see it's size, but when I try to show it
>(im.show()) I get a blank TK window and an error on the command line
>that says : Bad command or File name.
>
>Any idea what's wrong? I can import Image and ImageTk without any
>errors.
show is just for Unix. Try something like tht following:
from Tkinter import *
import Image, ImageTk
import tkFileDialog
class Open:
def __init__(self, parent):
self.canvas = Canvas(parent, bg='white')
self.canvas.pack(expand=1, fill='both')
b = Button(parent, command=self.open, text="Open")
b.pack()
def open(self):
filename = tkFileDialog.askopenfilename()
w, h = self.canvas.winfo_width(), self.canvas.winfo_height()
if filename != '':
self.graphic = Image.open(filename)
self.image = ImageTk.PhotoImage(image=self.graphic)
self.canvas.create_image(w/2, h/2, image=self.image)
if __name__ == "__main__":
root = Tk()
test = Open(root)
root.mainloop()
More information about the Python-list
mailing list