Call a class A method from a class B instance? Do I miss something?
jfong at ms4.hinet.net
jfong at ms4.hinet.net
Thu Aug 17 20:03:53 EDT 2017
More information about the Python-list mailing list
Thu Aug 17 20:03:53 EDT 2017
- Previous message (by thread): Synchronization Primitives in Python
- Next message (by thread): Call a class A method from a class B instance? Do I miss something?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): Synchronization Primitives in Python
- Next message (by thread): Call a class A method from a class B instance? Do I miss something?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list