user14483403
user14483403

Reputation:

Python tkinter canvas geometry

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

Upvotes: 1

Views: 1676

Answers (1)

Module_art
Module_art

Reputation: 1068

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()

Upvotes: 1

Related Questions