Is it possible to call a class but without a new instance created?
Jach Fong
jfong at ms4.hinet.net
Mon Jun 18 20:01:25 EDT 2018
It seems most of confusion comes from mixing up python object and tk
widgets, and ignored that the tkinter is really a python-tk-interface.
Thank you for pointing it out.
Terry Reedy at 2018/6/18 PM 05:19 wrote:
> To answer the question of the title, which is a bit different from the
> question in the text, yes. type(None)() always returns the singleton
> None object. (And one can write a singleton class in Python also.)
> bool() always returns one of False or True. int() and str() may return
> either a new or old object. For such immutables, it does not matter as
> long at the object has the correct value. As others said, this is all
> handled in a __new__ method. But none of this has much to do with
> tkinter instances.
>
> On 6/18/2018 5:09 AM, Terry Reedy wrote:
>> On 6/18/2018 12:48 AM, Jach Fong wrote:
>>> After looking into the \tkiniter\font.py source file, triggered by Jim's
>>> hint on my previous subject "Why an object changes its "address" between
>>> adjacent calls?", I get more confused.
>>>
>>> Below was quoted from the font.py:
>>> ------------------------
>>> def nametofont(name):
>>> """Given the name of a tk named font, returns a Font
>>> representation.
>>> """
>>> return Font(name=name, exists=True)
>>>
>>> class Font:
>>> """Represents a named font.
>>
>> tkinter abbreviates tk interface. A Python tkinter Font instance
>> represents a tk named font structure. It has a hidden pointer to the
>> tk structure. The same is true of all instances of tkinter widgets
>> classes. Each has a hidden pointer to a tk widget
>>
>>> Constructor options are:
>>> ...
>>> exists -- does a named font by this name already exist?
>>
>> Does a *tk* named font exist?
>>
>>> Creates a new named font if False, points to the existing
>>> font if True.
>>
>> Again, 'font' here means a tk structure, not a python instance. Each
>> call to Font returns a new python instance. But for Fonts, it may or
>> may not point to a new tk structure.
>>
>>> ...
>>> """
>>>
>>> def __init__(self, root=None, font=None, name=None, exists=False,
>>> **options):
>>> ...
>>
>> One can mostly ignore the parallel existence of python instances and
>> tk structures. But they can get out of sync during shutdown. If t is
>> an instance of Text, t.destroy() causes tkinter to tell tk to destroy
>> the tk widget, leaving t useless. Similarly, if 'del t' deletes the
>> last reference to the Python instance, it may disappear, leaving the
>> tk widget possibly unaccessible.
>>
>
>
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the Python-list
mailing list