Подскажите, как сделать передвижение овала нарисованного на холсте.
То есть у меня есть на холсте нарисованные овалы и по нажатию и перемещению мышкой выбранный овал тоже должен перемещаться.
Спасибо.
import Tkinter
from math import cos,sin
import time
tk = Tkinter
KOL = 10
class Canvas_1(tk.Frame):
def __init__(self, master,kol):
print kol
self.master = master
self.loc = self.dragged = 0
tk.Frame.__init__(self, master)
canvas = tk.Canvas(self, width =900, height =900,
relief =tk.RIDGE, background ="white", borderwidth =1)
x_center = 350
y_center = 350
r = 300
s=0
for i in range(1,kol+1,1):
s=s+(360./kol)
id=canvas.create_oval (x_center+r*sin(s)-5,y_center+r*cos(s)-5,x_center+r*sin(s)+5,y_center+r*cos(s)+5,
fill="red", tags ="DnD")
canvas.pack (expand =1, fill =tk.BOTH)
canvas.tag_bind ("DnD", "<ButtonPress-1>", self.down)
canvas.tag_bind ("DnD", "<ButtonRelease-1>", self.up)
canvas.tag_bind ("DnD", "<Enter>", self.enter)
canvas.tag_bind ("DnD", "<Leave>", self.leave)
def down (self, event):
self.loc =1
self.dragged =0
event.widget.bind ("<Motion>", self.motion)
def leave (self, event):
self.loc =0
def enter (self, event):
self.loc =1
self.up (event)
def motion (self, event):
root.config (cursor ="exchange")
cnv = event.widget
cnv.itemconfigure (tk.CURRENT, fill ="blue")
x,y = cnv.canvasx(event.x), cnv.canvasy(event.y)
got = event.widget.coords (tk.CURRENT, x-5, y-5, x+5, y+5)
def up (self, event):
event.widget.unbind ("<Motion>")
event.widget.itemconfigure (tk.CURRENT, fill ="blue")
print event.widget.itemcget(tk.CURRENT)
self.master.update()
time.sleep (.1)
event.widget.itemconfigure (tk.CURRENT, fill ="green")
print sin(10)
kol = input()
root = tk.Tk()
root.title("Tkinter canvas...")
Canvas_1 (root,kol).pack()
root.mainloop()