codehaus


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

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


David? 2019?9?8???? UTC+8??8?14?03????
> On Sun, 8 Sep 2019 at 21:05, <jfong at ms4.hinet.net> wrote:
> > David? 2019?9?8???? UTC+8??6?44?55????
> > > On Sun, 8 Sep 2019 at 20:25, <jfong at ms4.hinet.net> wrote:
> 
> > > > If I have two widgets created this way:
> > > > t0 = tkinter.Text()
> > > > t1 = tkinter.Text()
> > > > How many Tk objects will there be?
> 
> > Sorry, didn't make it clear. I mean <tkinter.Tk object .>
> 
> Sorry I didn't read more carefully.
> But I think that the method I demonstrated can give
> the answer to your question.
> 
> >>> import tkinter
> >>> t0 = tkinter.Text()
> >>> t1 = tkinter.Text()
> >>> t0.master
> <tkinter.Tk object .>
> >>> t1.master
> <tkinter.Tk object .>
> >>> t0.master is t1.master
> True
> >>>

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:-)

--Jach