简体   繁体   中英

Is there a way to label an oval (canvas.create_oval) in Tkinter?

I have a canvas :

window = tk.Tk()
canvas = tk.Canvas(window,
              width=width,
              height=height,
              bg='black')

With an oval :

canvas.create_oval(x1, y1, x2, y2, fill='red')

Is it possible to label this oval as such:

在此处输入图片说明

*Keep in mind the oval in this image has a line coming out which is irrelevant to this question

One way to do it is to use create_text :

x = abs((x1-x2)/2)
y = abs((y1-y2)/2)
oval_label = canvas.create_text((x, y), text="Label text")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM