Home > Software design >  How to draw on an image Tkinter canvas, PIL
How to draw on an image Tkinter canvas, PIL

Time:05-17

I would want to be able to draw on an image being displayed by a tkinter canvas PIL. I tried google searching but all the results would be how to draw on an image without tkinter or how to display an image which is not what i want. I also would like it to be like live(color while i move my mouse). Is there any way to do this. If there are no ways with PIL is there a way with tkinter.

CodePudding user response:

I think the best approach would be to do the drawing with tkinter because otherwise you will need to continually update the canvas widget every time the image gets changed by the PIL (which might be too slow and interfere with "live" drawing).

tkinter Canvases have several different vector and text drawing capabilities, and you can draw/display them on top of an image that's also being displayed by it. This means if you first add an image, anything further that is drawn will appear on top of that (if it overlaps the image).

Below is a demonstration of doing that. Note I borrowed some of the code and the sample image from the screenshot

  • Related