I've created an image with PIL, and I'm trying to get it show on a Tkinter GUI, but I get a blank window. Any ideas?

import Tkinter
import Image, ImageTk, ImageDraw

#create an image

image = Image.new('RGBA', (100, 100))
i = 0
draw = ImageDraw.Draw(image)
## draw some lines
for i in range(1,10):
	draw.line((0,i * 10) + image.size, fill=128)

##############

def button_click_exit_mainloop (event):
    event.widget.quit() # this will cause mainloop to unblock.

root = Tkinter.Tk()
root.bind("<Button>", button_click_exit_mainloop)
root.geometry('100x100')

#load the image we created before
tkpi = ImageTk.PhotoImage(image)
label_image = Tkinter.Label(root, image=tkpi)
label_image.place(x=0,y=0,width=150,height=150)
label_image.pack()
input()

Try to save your image drawing to a GIF file and then load that file ...

import Tkinter
from PIL import Image, ImageTk, ImageDraw

image_file = "aatest.gif"

#create an image

image = Image.new('RGBA', (200, 200))
draw = ImageDraw.Draw(image)
## draw some lines
for i in range(1,10):
    draw.line((0, i * 10) + image.size, fill=128)

image.save(image_file)

##############

def button_click_exit_mainloop (event):
    event.widget.quit() # this will cause mainloop to unblock.

root = Tkinter.Tk()
root.bind("<Button>", button_click_exit_mainloop)
root.geometry('300x300')

#load the image file we created before
tkpi = ImageTk.PhotoImage(file=image_file)
label_image = Tkinter.Label(root, image=tkpi)
#label_image.place(x=0,y=0,width=150,height=150)
label_image.pack()
#input()

root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.