PATH:
usr
/
lib64
/
python2.7
/
Demo
/
tkinter
/
matt
from Tkinter import * # this file demonstrates the movement of a single canvas item under mouse control class Test(Frame): ################################################################### ###### Event callbacks for THE CANVAS (not the stuff drawn on it) ################################################################### def mouseDown(self, event): # remember where the mouse went down self.lastx = event.x self.lasty = event.y def mouseMove(self, event): # whatever the mouse is over gets tagged as CURRENT for free by tk. self.draw.move(CURRENT, event.x - self.lastx, event.y - self.lasty) self.lastx = event.x self.lasty = event.y ################################################################### ###### Event callbacks for canvas ITEMS (stuff drawn on the canvas) ################################################################### def mouseEnter(self, event): # the CURRENT tag is applied to the object the cursor is over. # this happens automatically. self.draw.itemconfig(CURRENT, fill="red") def mouseLeave(self, event): # the CURRENT tag is applied to the object the cursor is over. # this happens automatically. self.draw.itemconfig(CURRENT, fill="blue") def createWidgets(self): self.QUIT = Button(self, text='QUIT', foreground='red', command=self.quit) self.QUIT.pack(side=LEFT, fill=BOTH) self.draw = Canvas(self, width="5i", height="5i") self.draw.pack(side=LEFT) fred = self.draw.create_oval(0, 0, 20, 20, fill="green", tags="selected") self.draw.tag_bind(fred, "<Any-Enter>", self.mouseEnter) self.draw.tag_bind(fred, "<Any-Leave>", self.mouseLeave) Widget.bind(self.draw, "<1>", self.mouseDown) Widget.bind(self.draw, "<B1-Motion>", self.mouseMove) def __init__(self, master=None): Frame.__init__(self, master) Pack.config(self) self.createWidgets() test = Test() test.mainloop()
[-] canvas-gridding.py
[edit]
[-] radiobutton-simple.py
[edit]
[-] canvas-gridding.pyc
[edit]
[-] two-radio-groups.pyo
[edit]
[-] rubber-band-box-demo-1.py
[edit]
[-] rubber-line-demo-1.py
[edit]
[-] canvas-moving-or-creating.pyo
[edit]
[-] 00-HELLO-WORLD.py
[edit]
[-] window-creation-w-location.pyc
[edit]
[-] canvas-moving-w-mouse.py
[edit]
[-] animation-simple.py
[edit]
[-] canvas-moving-w-mouse.pyc
[edit]
[-] canvas-moving-w-mouse.pyo
[edit]
[-] animation-w-velocity-ctrl.py
[edit]
[+]
..
[-] canvas-demo-simple.pyc
[edit]
[-] not-what-you-might-think-2.pyc
[edit]
[-] packer-simple.pyc
[edit]
[-] two-radio-groups.py
[edit]
[-] rubber-line-demo-1.pyc
[edit]
[-] menu-all-types-of-entries.py
[edit]
[-] killing-window-w-wm.pyc
[edit]
[-] README
[edit]
[-] canvas-moving-or-creating.pyc
[edit]
[-] animation-simple.pyo
[edit]
[-] packer-and-placer-together.py
[edit]
[-] animation-w-velocity-ctrl.pyc
[edit]
[-] pong-demo-1.pyc
[edit]
[-] rubber-band-box-demo-1.pyc
[edit]
[-] two-radio-groups.pyc
[edit]
[-] menu-all-types-of-entries.pyc
[edit]
[-] slider-demo-1.py
[edit]
[-] packer-simple.py
[edit]
[-] printing-coords-of-items.pyo
[edit]
[-] dialog-box.pyo
[edit]
[-] entry-simple.pyo
[edit]
[-] subclass-existing-widgets.pyc
[edit]
[-] window-creation-more.pyc
[edit]
[-] dialog-box.pyc
[edit]
[-] not-what-you-might-think-1.pyc
[edit]
[-] radiobutton-simple.pyo
[edit]
[-] canvas-moving-or-creating.py
[edit]
[-] placer-simple.pyc
[edit]
[-] menu-simple.pyo
[edit]
[-] rubber-band-box-demo-1.pyo
[edit]
[-] canvas-gridding.pyo
[edit]
[-] placer-simple.py
[edit]
[-] animation-w-velocity-ctrl.pyo
[edit]
[-] canvas-reading-tag-info.pyo
[edit]
[-] canvas-with-scrollbars.pyc
[edit]
[-] killing-window-w-wm.py
[edit]
[-] window-creation-w-location.py
[edit]
[-] not-what-you-might-think-2.pyo
[edit]
[-] entry-simple.pyc
[edit]
[-] entry-simple.py
[edit]
[-] rubber-line-demo-1.pyo
[edit]
[-] subclass-existing-widgets.pyo
[edit]
[-] window-creation-simple.pyo
[edit]
[-] canvas-mult-item-sel.pyo
[edit]
[-] window-creation-simple.pyc
[edit]
[-] canvas-w-widget-draw-el.pyc
[edit]
[-] canvas-with-scrollbars.pyo
[edit]
[-] window-creation-more.pyo
[edit]
[-] canvas-mult-item-sel.pyc
[edit]
[-] canvas-reading-tag-info.pyc
[edit]
[-] killing-window-w-wm.pyo
[edit]
[-] bind-w-mult-calls-p-type.pyo
[edit]
[-] entry-with-shared-variable.py
[edit]
[-] 00-HELLO-WORLD.pyc
[edit]
[-] canvas-with-scrollbars.py
[edit]
[-] pong-demo-1.pyo
[edit]
[-] window-creation-more.py
[edit]
[-] slider-demo-1.pyc
[edit]
[-] menu-simple.py
[edit]
[-] animation-simple.pyc
[edit]
[-] subclass-existing-widgets.py
[edit]
[-] canvas-w-widget-draw-el.pyo
[edit]
[-] packer-and-placer-together.pyc
[edit]
[-] bind-w-mult-calls-p-type.pyc
[edit]
[-] not-what-you-might-think-1.py
[edit]
[-] not-what-you-might-think-2.py
[edit]
[-] window-creation-simple.py
[edit]
[-] canvas-mult-item-sel.py
[edit]
[-] bind-w-mult-calls-p-type.py
[edit]
[-] entry-with-shared-variable.pyc
[edit]
[-] radiobutton-simple.pyc
[edit]
[-] dialog-box.py
[edit]
[-] menu-all-types-of-entries.pyo
[edit]
[-] canvas-demo-simple.pyo
[edit]
[-] menu-simple.pyc
[edit]
[-] slider-demo-1.pyo
[edit]
[-] canvas-w-widget-draw-el.py
[edit]
[-] 00-HELLO-WORLD.pyo
[edit]
[-] canvas-demo-simple.py
[edit]
[-] packer-simple.pyo
[edit]
[-] printing-coords-of-items.py
[edit]
[-] printing-coords-of-items.pyc
[edit]
[-] canvas-reading-tag-info.py
[edit]
[-] window-creation-w-location.pyo
[edit]
[-] not-what-you-might-think-1.pyo
[edit]
[-] pong-demo-1.py
[edit]
[-] entry-with-shared-variable.pyo
[edit]
[-] packer-and-placer-together.pyo
[edit]
[-] placer-simple.pyo
[edit]