1

I am trying to add an image to TopLevel using create_image. And I have an error: AttributeError: 'Toplevel' object has no attribute 'create_image'.

Can you help me solve this problem please?

koniec=Toplevel()
koniec.minsize(width=200, height=250)
koniec.title("Víťaz!")
img=tkinter.PhotoImage(file='obrazok.gif')
koniec.create_image(100,100,image=obr)
martineau
  • 119,623
  • 25
  • 170
  • 301
buxantiss
  • 13
  • 1
  • 3

1 Answers1

3

Toplevel doesn't have a create_image method, but Canvas does. You could add a Canvas to the Toplevel, and add your image to that.

koniec=Toplevel()
koniec.minsize(width=200, height=250)
koniec.title("Vítaz!")
canvas = Canvas(koniec, width=200, height=200)
canvas.pack()
img=tkinter.PhotoImage(file='obrazok.gif')
canvas.create_image(100,100,image=img)

Additionally, it may be necessary to have canvas.image = img, to prevent the PhotoImage garbage collection bug.

martineau
  • 119,623
  • 25
  • 170
  • 301
Kevin
  • 74,910
  • 12
  • 133
  • 166