Python HW9.3
unknown
python
3 years ago
995 B
15
Indexable
from math import sqrt
from tkinter import*
class circleCoordinate:
def __init__(self, x, y, tags):
self.tags = tags
self.x = x
self.y = y
class Circle:
def __init__(self):
self.root = Tk()
self.canvas = Canvas(self.root, width=400, height=250, bg='white')
self.canvas.pack()
self.count = 0
self.circleList = []
self.canvas.bind("<Button-1>", self.draw)
self.canvas.bind("<Button-3>", self.delete)
self.root.mainloop()
def draw(self, click):
self.count += 1
self.circleList.append(circleCoordinate(click.x, click.y, self.count))
self.canvas.create_oval(click.x-10, click.y-10, click.x+10, click.y+10, tags=self.count)
def delete(self, click):
for i in self.circleList:
if sqrt(pow((click.x - i.x), 2) + pow((click.y - i.y), 2)) < 10:
self.canvas.delete(i.tags)
Circle()Editor is loading...