Search code examples
pythonuser-interfacetkinter

How to add an image in Tkinter?


How do I add an image in Tkinter?

This gave me a syntax error:

root = tk.Tk()
img = ImageTk.PhotoImage(Image.open(path))
panel = tk.Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()

Solution

  • There is no "Syntax Error" in the code above - it either ocurred in some other line (the above is not all of your code, as there are no imports, neither the declaration of your path variable) or you got some other error type.

    The example above worked fine for me, testing on the interactive interpreter.