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?10???? UTC+8??11?43?05????
> On 9/9/2019 8:30 PM, jfong at ms4.hinet.net wrote:
> > Terry Reedy? 2019?9?9???? UTC+8??3?06?27????
> 
> >> There will only be one default Tk object, but there can be multiple Tk
> >> objects.
> 
> >>>> import tkinter as tk
> >>>> f0 = tk.Frame()
> 
> This causes creation of a default root
> 
> >>>> root0 = tk.Tk()
> 
> This creates another, hence two different objects.
> 
> >>>> f0.master
> > <tkinter.Tk object at 0x015AB6F0>
> >>>> root0
> > <tkinter.Tk object at 0x015ABE50>
> 
> >>>> import tkinter as tk
> >>>> root0 = tk.Tk()
> 
> This creates a root that is set as the default because there was not one 
> already.
> 
> >>>> f0 = tk.Frame()
> 
> The uses the default root which is root0, hence 1 object.
> 
> >>>> f0.master
> > <tkinter.Tk object at 0x0269B710>
> >>>> root0
> > <tkinter.Tk object at 0x0269B710>
> 
> -- 
> Terry Jan Reedy

Got it. The first Tk object is always the default one no matter where it was  created. The default one is always the one which the widget constructor refer to when required.

--Jach