簡體   English   中英

Tkinter:保存給定寬度的繪制線的坐標

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM