How To Put A Cropped Image On A Tkinter Canvas In Python
I found a lot of similar questions, but not quite the solution to this case : I want to Load an image file from disk Crop it (lazy or not) Place it on a TKinter canvas And oh, i
Solution 1:
There is ImageTk
module in PIL
.
from Tkinter import *
from PIL import Image, ImageTk
root = Tk()
canvas = Canvas(root, width=500, height=500)
canvas.pack()
im = Image.open("image.png")
cropped = im.crop((0, 0, 200, 200))
tk_im = ImageTk.PhotoImage(cropped)
canvas.create_image(250, 250, image=tk_im)
root.mainloop()
Post a Comment for "How To Put A Cropped Image On A Tkinter Canvas In Python"