0
votes

I just wondering what I should do to apply an image as background of my tkinter window. I want this window with a gif image in the background and a few buttons on top of it..

the error msg says: "x.image = bg_image.grid(row = 0, column = 0) AttributeError: 'PhotoImage' object has no attribute 'grid'"

do I need to import something else? whats wrong? I dont even know if this PhotoImage code is supported by this version of python (python 3.1.1)...

from tkinter import*

window = Tk()
window.title("ksdasndsnadn")

bg_image = PhotoImage(file ="pic.gif")
x = Label (image = bg_image)
x.image = bg_image.grid(row = 0, column = 0)


window.geometry("600x300")
app = Application(window)
window.mainloop()
1

1 Answers

2
votes

You need to apply the grid method to the label that contains the image, not the image object:

bg_image = PhotoImage(file ="pic.gif")
x = Label (image = bg_image)
x.grid(row = 0, column = 0)

http://effbot.org/tkinterbook/photoimage.htm