-1

Unable to create circle using tkinter canva

import tkinter

top = tkinter.Tk()
C = tkinter.Canvas(top, bg="black", height=200, width=200)
coord = 50, 50, 150, 150
C.create_circle(coord,fill="blue")
C.pack()

top.mainloop()

Error:

   C.create_circle(coord,start=45,fill="blue")
AttributeError: 'Canvas' object has no attribute 'create_circle'
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
ritik047
  • 7
  • 2

2 Answers2

1

The name of the method is create_oval, not create_circle.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
0

You can't draw circle with tkinter directly so "Monkey patching" trick can help you and here is the modified code:

import tkinter as tk

top = tk.Tk()

C = tk.Canvas(top, bg="black", height=200, width=200)

C.grid()

def _create_circle(self, x, y, r, **kwargs):
    return self.create_oval(x-r, y-r, x+r, y+r, **kwargs)
tk.Canvas.create_circle = _create_circle

def _create_circle_arc(self, x, y, r, **kwargs):
    if "start" in kwargs and "end" in kwargs:
        kwargs["extent"] = kwargs["end"] - kwargs["start"]
        del kwargs["end"]
    return self.create_arc(x-r, y-r, x+r, y+r, **kwargs)
tk.Canvas.create_circle_arc = _create_circle_arc

C.create_circle(100, 120, 50, fill="blue", outline="#DDD", width=4)
C.create_circle_arc(100, 120, 48, fill="green", outline="", start=45, end=140)
C.create_circle_arc(100, 120, 48, fill="green", outline="", start=275, end=305)
C.create_circle_arc(100, 120, 45, style="arc", outline="white", width=6, start=270-25, end=270+25)
C.create_circle(150, 40, 20, fill="#BBB", outline="")

top.wm_title("Circles and Arcs")
top.mainloop()

You can check this answer for more clarification

Ahmed Arafa
  • 450
  • 3
  • 5