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

Time:10-13

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:

enter image description here

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

CodePudding user response:

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")
  • Related