1

Please help me to make my third oval round... I am changing values since hour but no luck:((

import tkinter as tk



root = Tk()



canvas = tk.Canvas(root, width=52, height=160)
canvas.place(x=0, y=10)

oval_red = canvas.create_oval(10, 5, 50, 50, fill="white")
oval_yellow = canvas.create_oval(10, 100, 50, 55, fill="white")
oval_green = canvas.create_oval(10, 205, 60, 100, fill="white")


canvas.itemconfig(oval_red, fill="red")
root.mainloop()


  [1]: https://i.sstatic.net/u5xHM.png
6
  • What do you mean with "make my third oval round"? Commented Nov 26, 2020 at 21:46
  • third, be like first and second, please see the figure attached Commented Nov 26, 2020 at 21:48
  • Instead of an oval you want a circle? Commented Nov 26, 2020 at 21:49
  • yes, exact circle Commented Nov 26, 2020 at 21:51
  • but the first and second aren't circles they are oval Commented Nov 26, 2020 at 21:57

1 Answer 1

1

You can make an oval to become a circle by adjusting the coordinates.

An ellipse is defined by rectangle coordinates.

canvas.create_oval(x0, y0, x1, y1, ...)

x0 and y0 are the top-left corner of the rectangle

x1 and y1 are the bottom-right corner of the rectangle

Your problem is easy math (addition and subtraction).

enter image description here

from tkinter import Tk, Canvas

root = Tk()
canvas = Canvas(root, width=400, height=400)
canvas.place(x=0, y=10)

oval_red = canvas.create_oval(10, 5, 50, 50, fill="white")      #this is an ellipse
oval_yellow = canvas.create_oval(10, 100, 50, 55, fill="white") #this is an ellipse
oval_green = canvas.create_oval(10, 110, 60, 160, fill="white") #this is a circle
canvas.itemconfig(oval_red, fill="red")

root.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.