0

trying to add a dynamic image tied to a StringVar variable in tkinter but the image is not shown on the screen

it is in a label inside a ttk.LabelFrame, which in theory should work

enter image description here

        # Hand
        handsContainner = ttk.LabelFrame(text='Hero Hand')
        handsContainner.grid(row=2, column=0, **self.centeredPaddings)
        handsContainner.rowconfigure(index=0,weight=1)
        handsContainner.columnconfigure(index=0,weight=1)
        handsContainner.columnconfigure(index=1,weight=1)
        
        photo = tk.PhotoImage(file='./cards/4h.png')
        firstCard = ttk.Label(handsContainner, image=photo)
        firstCard.grid(row=0,column=0)

what's the best way to do this thinking of reading a dataframe, and with each update of the variables to reload the correct image linked to them?

Collaxd
  • 425
  • 3
  • 12
  • 2
    If the code for creating and placing the image is in a function, then the variable must be saved so that it is not eaten by the garbage collector. https://web.archive.org/web/20201111190625id_/http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm – Сергей Кох Sep 25 '22 at 14:44
  • ye thats solve my problem to add images, now I need something like 'dinamic' images, but I'll open another quest, ty for that – Collaxd Sep 25 '22 at 15:12

0 Answers0