【发布时间】:2017-09-10 23:56:37
【问题描述】:
我正在研究自动机理论,我被要求编写一个自动机的图形(树),它看起来或多或少像:
到目前为止,我得到了这个(我正在使用 tkinter 和 canvas 来绘制):
from tkinter import Tk, Canvas, mainloop
def circle(canvas, x, y, r, width):
id = canvas.create_oval (x-r, y-r, x+r, y+r, width = width)
return id
def line (canvas, x1, y1, x2, y2, width):
canvas.create_line (x1, y1, x2, y2, width = width)
def text (canvas, x, y, text):
canvas.create_text (x, y, text = text, font = ("bold", 20))
w = Canvas(Tk (), width=1000, height=600, bg = "white")
circle (w , 150, 300, 70, 3)
circle (w , 150, 300, 50, 3)
circle (w , 370, 300, 70, 3)
circle (w , 640, 300, 70, 3)
circle (w , 910, 300, 70, 3)
line (w, 10, 300, 80, 300, 3)
circle (w, 73, 300, 5, 6)
line (w, 220, 300, 300, 300, 3)
circle (w, 293, 300, 5, 6)
line (w, 440, 300, 570, 300, 3)
circle (w, 567, 300, 5, 6)
line (w, 710, 300, 840, 300, 3)
circle (w, 837, 300, 5, 6)
text (w, 150, 300, "q0")
text (w, 370, 300, "q1")
text (w, 640, 300, "q2")
text (w, 910, 300, "q3")
w.pack()
mainloop()
显示这个:
我不需要箭头,因为我将使用点来代替。问题是我需要从圆 q3 到圆 q0 以及从圆 q0 到圆 q0 画一条线(“圆环”)。我尝试了canvas.create_arc() 方法,但我无法掌握它。有替代方案吗?关于如何绘制“bucle”的任何想法?
【问题讨论】:
-
canvas.create_arc()方法你有什么不明白的地方?要具体,或者更好的是,展示您使用它的尝试。顺便说一句,canvas.create_line()方法支持箭头。 -
我不明白该方法需要的坐标,所以我可以在任何圆上画一个圆环(我认为它是起点、终点和高度)。我如何画箭头?谢谢!
-
你读过这个吗? infohost.nmt.edu/tcc/help/pubs/tkinter/web/create_arc.html “画布上的弧形对象,最一般的形式,是从椭圆中取出的楔形切片。...点 (x0, y0) 是左上角,(x1, y1)椭圆适合的矩形的右下角。如果这个矩形是正方形,你会得到一个圆形。"
-
" extent : 切片的宽度(以度为单位)。切片从 start 选项给出的角度开始,逆时针扩展为 extent 度数。"
-
@jcfollower:FWIW,您以原始形式提供的链接与我原始评论中的第一个超链接相同。也许你应该更仔细地阅读……
标签: python canvas tkinter graphics tree