here2share

# Tk_def_open_image.py -- hack

May 28th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. # Tk_def_open_image.py
  2.  
  3. from Tkinter import *
  4. import tkFileDialog
  5. from PIL import ImageTk, Image
  6.  
  7. root=Tk()
  8. canvas=Canvas(root)
  9. canvas.grid(row=0, column=0)
  10. oFiletypes =("png files","*.png"),("all files","*.*")
  11. def browse():
  12.     """Convert a file (specified by a path) into a data URI."""
  13.     path = tkFileDialog.askopenfilename(title = "Select file",filetypes=oFiletypes)
  14.     photo=ImageTk.PhotoImage(file=path)
  15.     label = Label(image=photo)
  16.     label.image = photo # keeps the reference!
  17.     canvas.create_image(120, 120, image=label.image)
  18. browse()
  19. root.mainloop()
Add Comment
Please, Sign In to add comment