Here’s the issue –
I’m writing a program that will iterate through a series of image manipulations – both effecting the whole image as well as just portions of the image. I need to demonstrate these changes to the user (myself) so I can see what’s going wrong with my manipulations as they take place.
I originally tried to use PIL and Tkinter to do this – but I couldn’t even load an image into the GUI – here’s a bit of code formed from the corners of the web, via many google searches:
from Tkinter import *
import Image, ImageDraw, ImageTk
import time
class Test(Frame):
def __init__(self):
Frame.__init__(self)
self.c = Canvas(self, width=574, height=431, bg="red")
self.c.pack()
Button(self, text="Process", command=self.procImg).pack()
Button(self, text="Quit", command=self.quit).pack()
def procImg(self):
t = time.time()
self.flashImg = Image.open("./in_img/resize.bmp")
#self.flashImg = flashImg.resize((574, 431))
self.flashImg = self.flashImg.convert("L")
#self.photo = ImageTk.BitmapImage(flashImg)
self.c.photo = ImageTk.PhotoImage(self.flashImg)
self.c.create_image(574, 431, anchor=NW, image=self.c.photo)
self.c.create_rectangle(50, 50, 100, 100, fill="blue")
self.update()
print time.time()-t
t = Test()
t.pack()
t.mainloop()
So the above code is pretty bad, I know – but I wanted to post something to prove that I have at least been working at this.
Can anyone suggest to me a new way of approaching this problem using Python? I’d rather not learn a different language – I’m new to the Tkinter library so if something else is better suited for this, I have no issues learning a new library.
Also, FYI, the “resize.bmp” image is a resized .JPG from a digital camera. I tried that one too and it didn’t work – I really need to find a way to flash bitmaps from memory to the screen in a GUI so I can adjust parameters as the processing is going on.
Thanks for your help!
The image is probably there. It’s just not visible.
Instead of :
try :
Also, if you keep a reference to the canvas image item, you can swap different images in and out.
eg. (self.canvasItem) below :