Is it 'fine' to instantiate a widget without parent parameter?
Terry Reedy
tjreedy at udel.edu
Mon Sep 9 23:42:43 EDT 2019
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
More information about the Python-list
mailing list