codehaus


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

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


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