3
# allows moving dots with multiple selection.
6
UNSELECTED_COLOR = "blue"
9
###################################################################
10
###### Event callbacks for THE CANVAS (not the stuff drawn on it)
11
###################################################################
12
def mouseDown(self, event):
13
# see if we're inside a dot. If we are, it
14
# gets tagged as CURRENT for free by tk.
16
if not event.widget.find_withtag(CURRENT):
17
# we clicked outside of all dots on the canvas. unselect all.
19
# re-color everything back to an unselected color
20
self.draw.itemconfig("selected", fill=UNSELECTED_COLOR)
22
self.draw.dtag("selected")
24
# mark as "selected" the thing the cursor is under
25
self.draw.addtag("selected", "withtag", CURRENT)
26
# color it as selected
27
self.draw.itemconfig("selected", fill=SELECTED_COLOR)
33
def mouseMove(self, event):
34
self.draw.move("selected", event.x - self.lastx, event.y - self.lasty)
39
# create a dot, and mark it as current
40
fred = self.draw.create_oval(0, 0, 20, 20,
41
fill=SELECTED_COLOR, tags=CURRENT)
42
# and make it selected
43
self.draw.addtag("selected", "withtag", CURRENT)
45
def createWidgets(self):
46
self.QUIT = Button(self, text='QUIT', foreground='red',
50
# make the canvas and bind some behavior to it
52
self.draw = Canvas(self, width="5i", height="5i")
53
Widget.bind(self.draw, "<1>", self.mouseDown)
54
Widget.bind(self.draw, "<B1-Motion>", self.mouseMove)
56
# and other things.....
57
self.button = Button(self, text="make a new dot", foreground="blue",
58
command=self.makeNewDot)
60
message = ("%s dots are selected and can be dragged.\n"
61
"%s are not selected.\n"
62
"Click in a dot to select it.\n"
63
"Click on empty space to deselect all dots."
64
) % (SELECTED_COLOR, UNSELECTED_COLOR)
65
self.label = Message(self, width="5i", text=message)
67
self.QUIT.pack(side=BOTTOM, fill=BOTH)
68
self.label.pack(side=BOTTOM, fill=X, expand=1)
69
self.button.pack(side=BOTTOM, fill=X)
70
self.draw.pack(side=LEFT)
72
def __init__(self, master=None):
73
Frame.__init__(self, master)