I'm trying to show a .png image in a canvas inside the main window, but what I get in the canvas is just a blue background. Please can you help me show the image instead of the blue background?
import os
import tkinter as tk
class MyApplication(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title('Program')
self.geometry('500x300')
folder = os.path.dirname(__file__)
self.canvas = tk.Canvas(self, bg='blue', height=300, width=300)
self.canvas.pack()
my_image = tk.PhotoImage(file=folder+'/1102157.png')
self.canvas.create_image(0, 0, anchor = tk.NW, image=my_image)
if __name__=='__main__':
app = MyApplication()
app.mainloop()
I tried to put
folder = os.path.dirname(__file__)
before the class MyApplication but it still does not work.