[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()

numboxes=6

width=40*(numboxes+2)
height=200
w = Canvas(master, width=width, height=height)
w.pack()

size=width/(numboxes+2)

box=[0]*numboxes

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

mainloop()



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