[Tutor] tkinter canvas

Mr Gerard Kelly s4027340 at student.uq.edu.au
Thu Jan 15 06:41:32 CET 2009

I am trying to make a simple Tkinter program using the canvas widget.
All it does take a number (6 in this case) and draw that number of blue
boxes on a canvas.

from Tkinter import *

master = Tk()


w = Canvas(master, width=width, height=height)



for i in range(numboxes):
  box[i]=w.create_rectangle((1+i)*40, 40, (2+i)*40, height-40, fill="blue")


I want to be able to bind these boxes to an event - so that I can either
click on them, or hold the mouse cursor over them, and have them change
color. However I haven't been able to find any examples of related
tkinter code on google, and the tutorials and documentation about
binding and events with canvas items is very confusing without being
able to see it used in examples. 

More information about the Tutor mailing list