Skip to content Skip to sidebar Skip to footer

Displaying The Selected Image Using Tkinter

I want to know whether I can display an image from the path I have selected? like, I have a path for example: c:\user\desktop\33.jpg, and I want to take only that jpg file and I ha

Solution 1:

Here is a sample code for what you are asking:

from Tkinter import Label,Tk
from PIL import Image, ImageTk
import tkFileDialog
root = Tk()

path=tkFileDialog.askopenfilename(filetypes=[("Image File",'.jpg')])
im = Image.open(path)
tkimage = ImageTk.PhotoImage(im)
myvar=Label(root,image = tkimage)
myvar.image = tkimage
myvar.pack()

root.mainloop()

You will be wanting to add a button for calling the askopenfilename because right now its calling it the moment the program begins. Also you might wanna add more file extensions to filetypes

Post a Comment for "Displaying The Selected Image Using Tkinter"