I am working on a Python program that lets the user discover New-Caledonia's works of art (it's a smallish French island in the Pacific Ocean :) ).
I try to call a function that stores an image. But after hours of research I found out this webpage describing the problem which I have. What happens is that Python garbages my image because I have to "keep an extra reference to the image object. A simple way to do this is to assign the image to a widget attribute." I tried to do it, but as I am a beginner, I don't really know how to do that.
Here is my script:
from tkinter import *
# Création de la fenêtre de menu
fenetre=Tk()
fenetre.title("ART'CAL")
Canevas=Canvas(fenetre, height=768,width=1346)
Canevas.pack()
# Insertion de l'image du menu
PhotoMenu = PhotoImage(file ='Diapositive1.gif')
Fond = Canevas.create_image(680, 350, image=PhotoMenu)
# Création de la fenêtre de règles du jeu
def Rules():
fenetre=Tk()
fenetre.title("Règles du jeu")
CanevasRules=Canvas(fenetre, height=768,width=1346)
CanevasRules.pack()
# Insertion de l'image des règles du jeu
PhotoRules = PhotoImage(file ='Diapositive2.gif')
Fond = CanevasRules.create_image(680, 350, anchor=CENTER, image=PhotoRules)
Suivant = Button(CanevasRules, text="Suivant")
Suivant.place(x=600, y=510)
Suivant.config(font=('Product Sans',20,'bold'))
# Création et personnalisaton du bouton "Découvrir"
Decouvrir = Button(Canevas, text="Découvrir")
Decouvrir.place(x=600, y=510)
Decouvrir.config(font=('Product Sans',20,'bold'), command=Rules)
fenetre.mainloop()
Everything works fine until I press DECOUVRIR ("Discover" in French). It doesn't display any image. Can anyone help me and show me how to display this image?