Image not showing properly

In my code, my image is showing up but it is gray. I can interact with it but it is not showing what I imported. I am using Tkinter and this is how my code looks.

  imgFrance = tk.PhotoImage(file="MapFrance.png")
  Image = tk.Label(Fenetre, image=imgFrance)

Here is my Replit if you want to check it out.

1 Like

Hello @VincentBilodea1 and welcome to the community!

You are not keeping a reference to the image object. In your Pays function, after you create the lblImage , you should add a line to attach the image to this label.

Take France, like you used in your example:

lblImage = tk.Label(Fenetre, image=imgFrance)
lblImage.image = imgFrance  # Keep a reference

You should do the same for the other cases (like, the countries). This way, the image object remains in memory as long as the label exists, and the image will be displayed correctly.

Thank You very much!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.