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

Terry Reedy tjreedy at udel.edu
Mon Sep 9 03:06:04 EDT 2019


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




More information about the Python-list mailing list