Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_def_open_image.py
- from Tkinter import *
- import tkFileDialog
- from PIL import ImageTk, Image
- root=Tk()
- canvas=Canvas(root)
- canvas.grid(row=0, column=0)
- oFiletypes =("png files","*.png"),("all files","*.*")
- def browse():
- """Convert a file (specified by a path) into a data URI."""
- path = tkFileDialog.askopenfilename(title = "Select file",filetypes=oFiletypes)
- photo=ImageTk.PhotoImage(file=path)
- label = Label(image=photo)
- label.image = photo # keeps the reference!
- canvas.create_image(120, 120, image=label.image)
- browse()
- root.mainloop()
Add Comment
Please, Sign In to add comment