On Wed, 16 Nov 2005 11:45:17 -0800
"Russell E. Owen" <[EMAIL PROTECTED]> wrote:

> In article <[EMAIL PROTECTED]>,
>  Michael Lange <[EMAIL PROTECTED]> wrote:
> 
> > ...I just wondered if there is a way to ...access the associated python 
> > callback from the tk command 
> > string...
> 
> I hope this helps. I've appended code that registers python functions to 
> be called from tcl/tk. This is from my RO python package 
> <http://www.astro.washington.edu/rowen/>, from RO.TkUtil.
> 

Thanks Russell,

In the meantime I jfound another way to achieve what I want; I store the python 
comands in a _callbacks dictionary with
the tk command strings as keys. I had to write a hacked version of _bind() for 
that, but I had to
do so anyway. After the line

     cmd = ('if {"[%s %s]" == "break"} break\n' % (funcid, 
self._subst_format_str_dnd))

in _bind() I added

     self._callbacks[cmd] = func

so I can do now something like:

    def deliver_event(self, event, sequence):
        res = 'break'
        tclCmd = self.bind(sequence)
        try:
             callback = self._callbacks[tclCmd]
             res = callback(event)
        except KeyError:
             pass
        return res

Then I can write handlers for several events like this:

    def deliver_sequence1(self, event):
        return self.deliver_event(event, sequence1)

This seems to work pretty well.

Regards

Michael


_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to