> Recently I posted, on this Forum, a msg titled: "Tkinter mouse- > event w/o class and/or global?" It was successfuly [RESOLVED] . > > ow I have related Question: > > I have two (c1 & c2) Canvas instances. If I mouse-click on one of the > canvases (or more likely on a drawn item on the canvas, e.g. on a > rectangle), I would like to change the background color of the other > canvas. > > Can I do it without classes (OOP) and/or global-variables? >
Sure can, you just have to pass the widget id as a parameter to the function. For example: import Tkinter as tk root = tk.Tk() c1 = tk.Canvas(root, bg='green') c2 = tk.Canvas(root, bg='red') c1.pack() c2.pack() def changeColour(event, c): if c.cget('bg') == 'red': c.configure(bg='green') else: c.configure(bg='red') c1.bind('<Button-1>', lambda e, c=c2: changeColour(e, c)) c2.bind('<Button-1>', lambda e, c=c1: changeColour(e, c)) root.mainloop() Regards, John _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss