codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is it 'fine' to instantiate a widget without parent parameter?


Terry Reedy? 2019?9?9???? UTC+8??3?06?27????
> On 9/8/2019 8:40 PM, jfong at ms4.hinet.net wrote:
> 
> > Thank you. After a quick trace to find out the reason, I found that Tkinter prevents Tk() be called more than once from widget constructors, so only one Tk object exists:-)
> 
> There will only be one default Tk object, but there can be multiple Tk 
> objects.
> 
>  >>> import tkinter as tk
>  >>> r1 = tk.Tk()
>  >>> r2 = tk.Tk()
>  >>> r1.tk
> <_tkinter.tkapp object at 0x000001F90F2F1D30>
>  >>> r2.tk
> <_tkinter.tkapp object at 0x000001F90F328930>
> 
> 
> -- 
> Terry Jan Reedy

>>> import tkinter as tk
>>> f0 = tk.Frame()
>>> root0 = tk.Tk()
>>> f0.master
<tkinter.Tk object at 0x015AB6F0>
>>> root0
<tkinter.Tk object at 0x015ABE50>
>>>

>>> import tkinter as tk
>>> root0 = tk.Tk()
>>> f0 = tk.Frame()
>>> f0.master
<tkinter.Tk object at 0x0269B710>
>>> root0
<tkinter.Tk object at 0x0269B710>
>>>

Why?

PS. Maybe there is no why, just it is what it is:-)

--Jach