-1

The following program will not run because the file 'python.gif' is not recognised.

from tkinter import *
window = Tk()
window.title( 'Image Example' )
img = PhotoImage( file = 'python.gif' )
label = Label( window , image = img , bg = 'yellow' )
small_img = PhotoImage.subsample( img, x = 2, y = 2 )
btn = Button( window, image = small_img )
txt = text( window, width = 25, height = 7 )
txt.image_create( '1.0', image = small_img )
txt.insert( '1.1' , 'Python Fun!' )
can = Canvas( window , width = 100 , height = 100 , bg = 'cyan' )
can.create_image( ( 50, 50 ),  image = small_img )
can.create_line( 0 , 0 , 100 , 100, width = 25 , fill = 'yellow' )
label.pack( side = TOP)
btn.pack( side = LEFT, padx  = 10 )
txt.pack( side = LEFT )
can.pack( side = LEFT, padx = 10 )
window.mainloop()
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
CodePY
  • 1

1 Answers1

0

Tkinter doesn't automatically show animated gifs. You will have to do the animation yourself by loading each frame in a loop.

See Play Animations in GIF with Tkinter

If your problem is that you're not seeing any image at all, it's probably due to the image being garbage-collected.

See Cannot Display an Image in Tkinter

Montresor
  • 806
  • 6
  • 22
  • Traceback (most recent call last): File "C:\Users\agard\Documents\Documents\MyCode\image.py", line 4, in img = PhotoImage( file = 'python.gif' ) File "C:\Users\agard\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 3393, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "C:\Users\agard\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 3349, in __init__ self.tk.call(('image', 'create', imgtype, name,) + options) _tkinter.TclError: couldn't recognize data in image file "python.gif" >>> ERROR – CodePY Dec 29 '20 at 19:11