I made a GUI for my model predicting my images after it was trained by CIFAR10 dataset. I want when I add the image to GUI, it appears on my Canvas area. However, the image was not shown. But when I click my 'classify' button, it still appears correct result. So it is definitely the display image problem. I also have searched and tried many way on the Internet but it did not help very well. Can someone tell me how to fix it? All comments are very appreciated. Thank you in advance!
My GUI when predicting. As you can see, it still has correct output, but the image doesn't show (it should show at the position of the white square - canvas)
My code:
# I just keep the overall structure of the code
# as some parts are not related to this problem
import ...
def get_image():
# Get path
path = askopenfilename(filetype=(("jpg file", "*.jpg"), ("png file", '*.png'), ("All files", "*.*"),))
# Load image
img = Image.open(path)
img = img.resize((350, 350))
img = ImageTk.PhotoImage(img)
return path, img
class App(tk.Tk):
def __init__(self):
# Code of 'browse' button
def add_image(self):
# Erase past record
self.delete_image()
# Load image
path, img = get_image()
# Display path and image
self.text.insert(END, path)
self.canvas.create_image(0, 0, anchor=NW, image=img)
def classify_image(self):
def delete_image(self):
app = App()
mainloop()