I'm trying to create an image, but it's not working and I'm not sure what I'm doing wrong. All I get when I click the button that should display the image is the white canvas, without the image. How do I get it to display?
def show_original(self):
from os.path import exists
from PIL import Image, ImageTk
if not os.path.exists(self.wdg_orig_file_name_.get()):
tkMessageBox.showinfo('Load','File does not exist:' + self.wdg_orig_file_name_.get())
return
self.orig_image_=Image.open(str_orig_file_name)
canvas = self.gui_.ca(500,500,bg='white')
im_TK = ImageTk.PhotoImage(self.orig_image_)
canvas.create_image(250,250,image=im_TK)
canvas.pack()
pass
self.wdg_orig_file_name_.get()
in the main loop is:
self.wdg_orig_file_name_ = self.gui_.en(text='boat.png')
The global str_orig_file_name
is assigned in pick_file()
:
def pick_file(self):
'''Opens a file dialog and sets its result to the filename entry'''
global str_orig_file_name
str_orig_file_name = tkFileDialog.askopenfilename()
if str_orig_file_name:
self.wdg_orig_file_name_.delete(0, END)
self.wdg_orig_file_name_.insert(0, str_orig_file_name)
#We got a new image to process. Forget the previous results.
self.orig_image_ = None
self.preview_image_ = None