Insert image inside a secondary window

0

How do I insert an image inside a window that will open after I click a button? I tried with the following code but I get the error:

Exception in Tkinter callback Traceback (most recent call last):   File "C:\Users\gt\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)   File "C:/Users/gt/PycharmProjects/teste/duvida.py", line 9, in botão_click
    label = Label(janela2, image=photo)   File "C:\Users\gt\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2763, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)   File "C:\Users\gt\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 2296, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage1" doesn't exist

Follow the code:

from tkinter import*
janela = Tk()

def botão_click():
    print('ok')
    janela2 = Tk()

    photo = PhotoImage(file = "aaa.png")
    label = Label(janela2, image=photo)
    label.pack()


botão = Button(janela, text="?", width=2, command=botão_click, background='red', font="arial 10 bold")
botão.place(x=90, y=70)

janela.mainloop()
    
asked by anonymous 03.06.2018 / 20:37

0 answers