Draw circle in Tkinter (Python)

前端 未结 2 1134
长情又很酷
长情又很酷 2020-12-24 13:29

Drawing a circle on a tkinter Canvas is usually done by the create_oval method. However, supplying the bounding box is often a confusing way to thi

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 14:09

    simpler solution:

    from tkinter import *
    root = Tk()
    myCanvas = Canvas(root)
    myCanvas.pack()
    
    def create_circle(x, y, r, canvasName): #center coordinates, radius
        x0 = x - r
        y0 = y - r
        x1 = x + r
        y1 = y + r
        return canvasName.create_oval(x0, y0, x1, y1)
    
    create_circle(100, 100, 20, myCanvas)
    create_circle(50, 25, 10, myCanvas)
    root.mainloop()
    

提交回复
热议问题