I study some codes of a tutorial about tkinter 
(https://github.com/daleathan/widget-tour-py3) and can't figure out how it 
works. 

Below is the codes from its two major files:
----------------------------
# file infrastructure.py
...
...
class callit:
    def __init__(self, function, *args ):
        self.f = function

        self.args = args


    def __call__(self, *ignored):
        self.f(*self.args)

...

------------------------
# file widget.py
...
from infrastructure import *
...
class DemoMainWindow(Frame):
    ...
    def _fill_textarea(self):
        ...
        # bind events
        self.text.tag_bind(tag, '<Any-Enter>',

             callit(self.demoenter_callback, tag) )
        ...

    def demoenter_callback(self, tag):
        ...
        self.text.configure(cursor='hand2')
        ...

----------------------
My question is that the object which was left by 
callit(self.demoenter_callback, tag) is a callit instance, and the method it 
calls is a DemoMainWindow's method.
How it is possible?


Best Regards,
Jach Fong
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to