George David King George David King - 1 month ago 7
Python Question

Import an image as a background in Tkinter

I've searched some other questions that many people did ask here about how can someone import an image as a background from Tkinter and I've got to say that I wasm't helped a lot.
Let me explain to you my problem. I have downloaded an image,converted it to gif and save it to my desktop.However can the Tkinter window opens up it does not import the image.
Here is my code:

import Tkinter as Tk
root = Tk.Tk()
background_image=Tk.PhotoImage("C:/Desktop/logo.gif")
background_label = Tk.Label(root, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
root.wm_geometry("600x400+20+40")
root.title('Menu')
playButton = Tk.Button(root, text='Play', command=root.destroy)
playButton.pack()
root.mainloop()


Are you able to help me?

Answer

You should use PhotoImage in this way.

background_image=Tk.PhotoImage(file="C:/Desktop/logo.gif")