Canvas Group object

John Grayson johngrayson at home.com
Tue Aug 8 07:22:27 EDT 2000


In article <8mmmgf$780$1 at nnrp1.deja.com>,
  Mike Olson <athos84 at my-deja.com> wrote:
> I am having an impossble time trying to get the the Canvas Group
object
> to work.  Can anyone help me debug this code?  It only binds the
> callback to clicking on the text, and not the rectangle, and I can't
see
> what I'm doing differently from all the examples I've seen:
>
> from Tkinter import *
> from Canvas import *
> from Canvas import Group
>
> class Card:
> 	def __init__(self, master):
> 		canvas = self.canvas = Canvas(master)
> 		canvas.pack()
> 		text="A Hearts"
> 		self.group = Group(canvas)
> 		self.rect = self.canvas.create_rectangle(10, 10, 85,
122, tags=text)
> 		self.txt = self.canvas.create_text(46, 15, text=text,
tags=text)
> 		self.group.addtag_withtag(self.rect)
> 		self.group.addtag_withtag(self.txt)
> 		self.group.bind("<Button-1>", self.callback)
>
> 	def callback(self, event=None):
> 		self.canvas.itemconfigure(self.rect, fill='red')
>
> root = Tk()
> app = Card(root)
> mainloop()
>

Not so, it works correctly!

The rectangle is *empty*. If you click on the line, you get the
callback. Most of the documents indicate that the default fill for a
canvas object is transparent. If you provide a non-blank initial fill,
you'll get the effect you want.

(BTW: don't use a stipple in an application like this, since you will
end up with a grid of sensitive and insensitive pixels...)

You've just made me realize that I omitted the Canvas Group object
from Python and Tkinter Programming. I'll have to add it in the
second edition. Thanks!

   John Grayson


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list