Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_img_askopenfilename.py
- import Tkinter as tk
- from tkFileDialog import askopenfilename
- from PIL import Image, ImageTk
- def openfile():
- global photo
- img_data = askopenfilename(filetypes=[('png files', '.png'), ('jpg files', '.jpg')])
- img = Image.open(img_data)
- photo = ImageTk.PhotoImage(img)
- canvas.itemconfig(cimage, image=photo)
- root = tk.Tk()
- canvas = tk.Canvas(root, height=500, width=500)
- cimage = canvas.create_image(0, 0, anchor=tk.NW, image="")
- canvas.pack()
- openfile()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement