Re: Is it 'fine' to instantiate a widget without parent parameter?
Terry Reedy於 2019年9月10日星期二 UTC+8下午5時16分19秒寫道: > On 9/10/2019 12:02 AM, jf...@ms4.hinet.net wrote: > > > 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. > > Or one can call tkinter.NoDefaultRoot() and not worry about default roots. > > -- > Terry Jan Reedy May I say this call has to be at the very beginning, before any widget was created using default root? And after this call, the 'parent' argument has to be explicitly assigned in the widget constructor? --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
On 9/10/2019 12:02 AM, jf...@ms4.hinet.net wrote: 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. Or one can call tkinter.NoDefaultRoot() and not worry about default roots. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
Terry Reedy於 2019年9月10日星期二 UTC+8上午11時43分05秒寫道: > On 9/9/2019 8:30 PM, jf...@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 > > > root0 > > > > 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 > > > root0 > > > > -- > 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 -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
On 9/9/2019 8:30 PM, jf...@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 root0 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 root0 -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
Terry Reedy於 2019年9月9日星期一 UTC+8下午3時06分27秒寫道: > On 9/8/2019 8:40 PM, jf...@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 0x01F90F2F1D30> > >>> r2.tk > <_tkinter.tkapp object at 0x01F90F328930> > > > -- > Terry Jan Reedy >>> import tkinter as tk >>> f0 = tk.Frame() >>> root0 = tk.Tk() >>> f0.master >>> root0 >>> >>> import tkinter as tk >>> root0 = tk.Tk() >>> f0 = tk.Frame() >>> f0.master >>> root0 >>> Why? PS. Maybe there is no why, just it is what it is:-) --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
On 9/8/2019 8:40 PM, jf...@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 0x01F90F2F1D30> >>> r2.tk <_tkinter.tkapp object at 0x01F90F328930> -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: 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, wrote: > > David於 2019年9月8日星期日 UTC+8下午6時44分55秒寫道: > > > On Sun, 8 Sep 2019 at 20:25, 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 > > 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 > > >>> t1.master > > >>> 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 -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
On Sun, 8 Sep 2019 at 21:05, wrote: > David於 2019年9月8日星期日 UTC+8下午6時44分55秒寫道: > > On Sun, 8 Sep 2019 at 20:25, 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 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 >>> t1.master >>> t0.master is t1.master True >>> -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
David於 2019年9月8日星期日 UTC+8下午6時44分55秒寫道: > On Sun, 8 Sep 2019 at 20:25, wrote: > > > > If I have two widgets created this way: > > t0 = tkinter.Text() > > t1 = tkinter.Text() > > How many Tk objects will there be? > > $ python3 > Python 3.5.3 (default, Sep 27 2018, 17:25:39) > [GCC 6.3.0 20170516] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import tkinter > >>> t0 = tkinter.Text() > >>> t1 = tkinter.Text() > >>> t0 is t1 > False > >>> t0 > > >>> t1 > > >>> Sorry, didn't make it clear. I mean --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
On Sun, 8 Sep 2019 at 20:25, wrote: > > If I have two widgets created this way: > t0 = tkinter.Text() > t1 = tkinter.Text() > How many Tk objects will there be? $ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> t0 = tkinter.Text() >>> t1 = tkinter.Text() >>> t0 is t1 False >>> t0 >>> t1 >>> -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
Terry Reedy於 2019年9月8日星期日 UTC+8下午5時31分34秒寫道: > On 9/7/2019 9:44 PM, jf...@ms4.hinet.net wrote: > > I know it is valid, according to the Tkinter source, every widget > > constructor has a 'master=None' default. What happens on doing this? > > Tkinter creates a default Tk object and uses that as the master. > > >>> t = tkinter.Text() > >>> t.master > > > > In what circumstance, we do it this way? and will it cause any trouble? > > I believe it is OK if you always do it that way within a single > application. But I prefer to have an explicit reference and use that > for .after calls and some others. > > > -- > Terry Jan Reedy If I have two widgets created this way: t0 = tkinter.Text() t1 = tkinter.Text() How many Tk objects will there be? --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Is it 'fine' to instantiate a widget without parent parameter?
On 9/7/2019 9:44 PM, jf...@ms4.hinet.net wrote: I know it is valid, according to the Tkinter source, every widget constructor has a 'master=None' default. What happens on doing this? Tkinter creates a default Tk object and uses that as the master. >>> t = tkinter.Text() >>> t.master In what circumstance, we do it this way? and will it cause any trouble? I believe it is OK if you always do it that way within a single application. But I prefer to have an explicit reference and use that for .after calls and some others. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Is it 'fine' to instantiate a widget without parent parameter?
I know it is valid, according to the Tkinter source, every widget constructor has a 'master=None' default. What happens on doing this? In what circumstance, we do it this way? and will it cause any trouble? --Jach -- https://mail.python.org/mailman/listinfo/python-list