作为@martineau cmets,create_arc() 是方法,但理解 tkinter 的 create_oval() 至关重要,因为弧是椭圆的一部分:
import tkinter as tk
WINDOW_WIDTH, WINDOW_HEIGHT = 600, 300
OVAL_WIDTH, OVAL_HEIGHT = 576, 290
# (x0, y0, x1, y1) rectangle for oval
BOUNDS = ( \
(WINDOW_WIDTH - OVAL_WIDTH) / 2, \
(WINDOW_HEIGHT - OVAL_HEIGHT) / 2, \
3*WINDOW_WIDTH/2 - OVAL_WIDTH/2, \
3*WINDOW_HEIGHT/2 - OVAL_HEIGHT/2 \
)
root = tk.Tk()
canvas = tk.Canvas(root, width=WINDOW_WIDTH+20, height=WINDOW_HEIGHT+20) # +20 for window "chrome"
canvas.pack()
rectangle = canvas.create_rectangle(*BOUNDS, outline="blue") # just for illustration
oval = canvas.create_oval(*BOUNDS, outline="red") # just for illustration
arc = canvas.create_arc(*BOUNDS, start=30, extent=120, style=tk.ARC, width=3)
root.after(3000, canvas.delete, rectangle) # remove rectangle illustration
root.after(6000, canvas.delete, oval) # remove oval illustration
root.mainloop()
当我使用 Arc 时,它会在底部创建一条线作为轮廓
弧线 - 我怎样才能摆脱它?
上面的style=tk.ARC 处理了这个问题——默认是一个饼图。
此弧的末端如何终止与您的插图不同。据我所知,tkinter 的 capstyle 和 joinstyle 选项不适用于 arcs。