[Tutor] Getting name of Widget for event.widget?

Leam Hall leamhall at gmail.com
Wed Jul 25 12:48:00 CEST 2012


Note that this is for an on-line class so I'd appreciate pointers to 
what I need to read or think about more than the answer out right.

Using Python 3 on Linux, is there a way to get the name of a widget 
instead of numeric representations in event.widget?

What I tried were a few variations of:

     def small_frame_handler1(self, event):
         print(event.widget, " clicked at ", event.x, event.y)

and got:

     .140937484.144713004  clicked at  350 39

Called by:

        frame1 = Frame(self, bg="blue")
        frame1.grid(row=0, column=0, rowspan=1, columnspan=2, sticky=ALL)
        frame1.bind("<Button-1>", self.small_frame_handler1)

I tried to send parameters in the "bind" but kept getting argument 
mis-matches. There are two frames and I'd like to be able to put the 
name of the frame in the print without having to have a separate method 
for each one. This is inside a class, if that makes a difference.

Thanks!

Leam


More information about the Tutor mailing list