4

I'm trying to use tkinter but this code doesn't work and I'm wondering if anyone knows why thanks.

from tkinter import *
window = Tk()
window.title("tkinter stuff")
photo1 = PhotoImage("file=hs.gif")
Label(window, image=photo1).grid(row=0,column=0,sticky=W)
window.mainloop()

Just to clarify, a window titled 'tkinter stuff' comes up but the image doesn't display. Also, there is a file called 'hs.gif' in the same folder as my code.

Thanks for the help

Bryan Oakley
  • 341,422
  • 46
  • 489
  • 636
Daniel
  • 59
  • 1
  • 2

2 Answers2

3

You need to move the quotes :

photo1 = PhotoImage(file="hs.gif")
PRMoureu
  • 12,299
  • 6
  • 35
  • 46
1

Below code serves as a example to your problem, and a clean way for using images as well. You can also configure background of window

import Tkinter as tk
from PIL import ImageTk, Image
window = tk.Tk()
window.title("tkinter stuff")
window.geometry("300x300")
window.configure(background='grey')
path = "hs.gif"
img = ImageTk.PhotoImage(Image.open(path))
panel = tk.Label(window, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
window.mainloop()
Chetan_Vasudevan
  • 2,354
  • 1
  • 11
  • 32