I have this code where the user can paint using his mouse:
from Tkinter import *
class Test:
def __init__(self):
self.b1="up"
self.xold=None
self.yold=None
def test(self,obj):
self.drawingArea=Canvas(obj)
self.drawingArea.pack()
self.drawingArea.bind("<Motion>",self.motion)
self.drawingArea.bind("<ButtonPress-1>",self.b1down)
self.drawingArea.bind("<ButtonRelease-1>",self.b1up)
def b1down(self,event):
self.b1="down"
def b1up(self,event):
self.b1="up"
self.xold=None
self.yold=None
def motion(self,event):
if self.b1=="down":
if self.xold is not None and self.yold is not None:
event.widget.create_line(self.xold,self.yold,event.x,event.y,fill="red",width=4,smooth=TRUE)
self.xold=event.x
self.yold=event.y
if __name__=="__main__":
root=Tk()
root.wm_title("Test")
v=Test()
v.test(root)
root.mainloop()
I wonder how to save the coordinates of the drawn line knowing that the thickness of the line is 4 (the width can be any integer number less than 10) ?
Without the thickness option, the answer is evident for me.
Thank you in advance.