Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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() 
like image 630
Damien Avatar asked Apr 13 '12 00:04

Damien


People also ask

Can you use JPG in Tkinter?

Images can be shown with tkinter. Images can be in a variety of formats including jpeg images.

Can Tkinter use PNG?

Tkinter PhotoImage only supports the GIF, PGM, PPM, and PNG file formats.


1 Answers

Python 3.3.1 [MSC v.1600 32 bit (Intel)] on win32 14.May.2013

This worked for me, by following the code above

from tkinter import * from PIL import ImageTk, Image import os  root = Tk() img = ImageTk.PhotoImage(Image.open("True1.gif")) panel = Label(root, image = img) panel.pack(side = "bottom", fill = "both", expand = "yes") root.mainloop() 
like image 193
josav09 Avatar answered Oct 06 '22 01:10

josav09