Drawing and Displaying an Image with PIL
Peter Otten
__peter__ at web.de
Wed Jan 28 07:58:09 EST 2009
W. eWatson wrote:
> r wrote:
>> Change this line:
>> draw.line((0,0),(20,140), fill=128)
>>
>> To This:
>> draw.line((0,0, 20,140), fill=128)
>>
>> And you should be good to go. Like you said, if you need to combine 2
>> tuples you can do:
>> (1,2)+(3,4)
> Yes, that's true, but the big question is how to "see" the final image?
> Either one employees another module or writes the file into a folder, then
> displays it with a paint program?
For debugging purposes you can just invoke the show() method
im = Image.open(...)
# modify image
im.show()
If you want to integrate the image into your own Tkinter program -- that is
explained here:
http://effbot.org/tkinterbook/photoimage.htm
Following these instruction you code might become
import Tkinter as tk
import Image
import ImageTk
import ImageDraw
import sys
filename = sys.argv[1]
im = Image.open(filename)
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line(((0,0),(20,140)), fill=128)
root = tk.Tk()
pi = ImageTk.PhotoImage(im)
label = tk.Label(root, image=pi)
label.pack()
root.mainloop()
Peter
More information about the Python-list
mailing list