I plan to write a program that allows the user to move shapes around on the canvas once they are drawn. A given shape will be drawn when an appropriate button is pressed. I'm using simple test programs to learn my way around. I've looked at a number of examples and I think the test code below should print the mouse coordinates when the shape is clicked. But it seems on_click() is never called. What am I doing wrong?
I'm using pythhon 2.7.6 on OSX 10.6.8
Thanks for your help.
import Tkinter as tk def on_click(e): print e.x, e.y def createShape(e): txt = e.widget.cget('text') cnvs.create_rectangle(10,10,75,60, tags="click") cnvs.tag_bind("click", '<ButtonPress-1>', on_click) cnvs.create_text(45, 40, text = txt) root = tk.Tk() root.wm_resizable(0,0) frame = tk.Frame(root, background="blue") frame.pack() cnvsHt = 800 cnvsWidth = 1000 cnvs = tk.Canvas(frame, width=cnvsWidth, height=cnvsHt, background = "#faf0e6") cnvs.pack() btnABC = tk.Button(frame, text="ABC", bg="blue", highlightbackground="blue", fg="white") btnABC.pack() btnABC.bind("<Button-1>", createShape) root.mainloop()
Edited 2 Years Ago by rbyrd