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

jfong at ms4.hinet.net jfong at ms4.hinet.net
Tue Sep 10 00:02:32 EDT 2019


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



More information about the Python-list mailing list