Python 3: Tkinter - Background image does not exist, "pyimage1" does not exist

0

My code for displaying a background image:

    from tkinter import *
    def entrar():
      #Janela Principal
      janela = Tk()
      janela.title("Salvadados")
      janela.geometry('400x600')
      #fotofundo
      back = Label(janela)
      back.la = PhotoImage(file = 'C:/Users/Ivan/Videos/fundim2.gif')
      back['image'] = back.la
      back.place(x=0,y=0)

The following error is displayed:

 **File "C:\Users\Ivan\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1473, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist**

Note: The enter () function is a command for a button to open this "Saved" window.

    
asked by anonymous 28.11.2018 / 14:01

1 answer

0

Hello, I'm not sure what you did in your code, but when I insert some image into some python program, Tkinter puts it like this:

#colocando a imagem
image = PhotoImage(file = 'C:\diretorio da sua imagem aqui')

#Mudando o tamanho(não sei se e util para voce, porem uso bastante)
image= image.subsample(2, 2)

#colocando dentro de uma label
lb = Label(image=image)
lb.place(bordermode=OUTSIDE, height=500, width=500)

I hope I have helped!

    
06.12.2018 / 00:38