D
D
Duckbill32132019-09-12 20:53:08
Python
Duckbill3213, 2019-09-12 20:53:08

How to insert a gif into a tkinter window?

I want to insert a gif into the tkinter window, and everything seems to be correct, but the console says that it does not find the file
Code:

import tkinter

ssw = tkinter.Tk()

def six():
    toplvl = tkinter.Toplevel() #created Toplevel widger
    photo = tkinter.PhotoImage(file = 'tenor.gif')
    lbl = tkinter.Label(toplvl ,image = photo)
    lbl.image = photo #keeping a reference in this line
    lbl.grid(row=0, column=0)

def base():
    la = tkinter.Button(ssw,text = 'yes',command=six)
    la.grid(row=0, column=0) #specifying row and column values is much better

base()

ssw.mainloop()

Error:
tkinter.TclError: couldn't open "tenor.gif": no such file or directory

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Allin, 2019-09-15
@DarkFox201561

Perhaps you did not put this project in the file with this gif and Python simply cannot find this gif, so it displays an error!
Example:
You make a project and a GIF in one file.
And you make code like this:

from tkinter import *
tk = Tk()
canvas = Canvas(tk, width=1000, height=800)
image = PhotoImage(file=r'D:\\файл\\файл\\гифка')
canvas.create_image(размер, размер, image=my_background, anchor='nw')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question