Member Avatar for rbyrd

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()
frame = tk.Frame(root, background="blue")

cnvsHt = 800
cnvsWidth = 1000
cnvs = tk.Canvas(frame, width=cnvsWidth, height=cnvsHt, background = "#faf0e6")

btnABC = tk.Button(frame, text="ABC", bg="blue", highlightbackground="blue", fg="white")
btnABC.bind("<Button-1>", createShape)


Only responds when you click on the border of the rectangle.
You have to fill the rectangle with eg. white to make the whole shape respond.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.