[英]Tkinter: save coordinates of a drawn line of a given width
我有以下代码,用户可以在其中使用鼠标进行绘制:
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()
我不知道知道线的粗细为4 (宽度可以是小于10的任何整数),如何保存绘制线的坐标?
如果没有厚度选项,答案对我来说是显而易见的。
先感谢您。
如果您想要的是绘制宽线时更改的所有像素的列表,则无法获得所需的信息。 在画布上创建线时,您获得的唯一信息是端点的坐标。
如果该线完全水平或垂直,则可以得到该线的边界框,但不适用于对角线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.