Advertisement
here2share

# Tk_img_askopenfilename.py

Mar 17th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. # Tk_img_askopenfilename.py
  2.  
  3. import Tkinter as tk
  4. from tkFileDialog import askopenfilename
  5. from PIL import Image, ImageTk
  6.  
  7.  
  8. def openfile():
  9.     global photo
  10.     img_data = askopenfilename(filetypes=[('png files', '.png'), ('jpg files', '.jpg')])
  11.     img = Image.open(img_data)
  12.     photo = ImageTk.PhotoImage(img)
  13.     canvas.itemconfig(cimage, image=photo)
  14.  
  15.  
  16. root = tk.Tk()
  17. canvas = tk.Canvas(root, height=500, width=500)
  18. cimage = canvas.create_image(0, 0, anchor=tk.NW, image="")
  19. canvas.pack()
  20. openfile()
  21. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement