How to get a unique id for bound methods?
Fredrik Lundh
fredrik at pythonware.com
Mon Aug 22 16:23:14 EDT 2005
Russell E. Owen wrote:
>>>The current issue is associated with Tkinter. I'm trying to create a tk
>>>callback function that calls a python "function" (any python callable
>>>entity).
>>>
>>>To do that, I have to create a name for tk that is unique to my python
>>>"function". A hash-like name would be perfect, meaning a name that is
>>>always the same for a particular python "function" and always different
>>>for a different python "function". That would save a lot of housekeeping.
have you tried Tkinter's built-in _register method?
>>> import Tkinter
>>> w = Tkinter.Tk()
>>> help(w._register)
Help on method _register in module Tkinter:
_register(self, func, subst=None, needcleanup=1) method of Tkinter.Tk
instance
Return a newly created Tcl function. If this
function is called, the Python function FUNC will
be executed. An optional function SUBST can
be given which will be executed before FUNC.
>>> def func():
... print "Hello"
...
>>> name = w._register(func)
>>> name
'10768336func'
>>> w.tk.call(name)
Hello
'None'
</F>
More information about the Python-list
mailing list