OOing in Tkinter - help

Paul Simmonds psimmo60 at hotmail.com
Thu Oct 10 11:37:36 CEST 2002


Henry Baumgartl wrote:
<snip>
>def onSelectAll(self, event=None):
>    self.textfield.tag_add(SEL, '1.0', END+'-1c')
>    self.textfield.mark_set(INSERT, '1.0')
>    self.textfield.see(INSERT)
>
>etc. However, now i need more than one Text widget in the same >container
>frame, and it seems a waste re-writing the methods to work with each 
> >widget.
>
>How can i adjust the above so it will respond to whatever text widget >the
>call comes from.
<snip>
You can use the event object that's created in the call. Swap your specific 
text widget call for the calling widget so the code becomes:

def onSelectAll(self, event=None):
    event.widget.tag_add(SEL, '1.0', END+'-1c')
    event.widget.mark_set(INSERT, '1.0')
    event.widget.see(INSERT)
    ...
The event object contains a lot of data on the calling widget. If this 
function is never called from anything other than a text widget (which it 
doesn't look like it will) then there'll be no problems.
HTH,
Paul


**********************************************
I used to have a handle on life, but it broke.
**********************************************


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com





More information about the Python-list mailing list