Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16268

Re: tkinter

Subject Re: tkinter
From Jason Swails <jason.swails@gmail.com>
Date 2011-11-26 18:10 -0500
References <f90bb247-8263-4cc1-a7a6-3f052e6de5dd@r28g2000yqj.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3062.1322349116.27778.python-list@python.org> (permalink)

Show all headers | View raw


The problem is that the logMode1 reference is _only_ bound to the name logMode1.  Assigning it to "variable" in the Checkbutton instance (logCheck1) does not actually generate a reference to that variable inside logCheck1.  Therefore, once the initialize method terminates, all references to logMode1 are destroyed and the variable is garbage-collected.

Therefore, that variable will be None by default, regardless of what you do to it inside "initialize", which is why the button appears unchecked.  If you create a reference to it, then the Checkbutton behaves as you'd expect (that is, it appears checked).  You can verify this easily by just making logMode1 an attribute of simpleapp_tk (replace logMode1 with self.logMode1 in every case).

You can also see this behavior by artificially lengthening the initialize method.  Import the time module and run "time.sleep(5)" at the end of initialize, and you will see the check button remain checked for 5 seconds (while the reference logMode1 survives), before the check vanishes as sleep ends and the reference leaves scope.

I would suggest that this is a checking feature rather than a bug.  The variable that you set is useless unless you plan to use the value (or if there's a case where you may use it).  If such a case exists, then you'll need a reference to that variable in the relevant scope you're dealing with.

Hope this helps,
Jason

On Nov 26, 2011, at 4:42 PM, Dave wrote:

> http://forums.devshed.com/python-programming-11/setting-tkinter-checkbox-default-graphical-state-865148.html
> Please answer this question I failed to resolve.
> Thanks,
> Dave.
> -- 
> http://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

tkinter Dave <b49P23TIvg@stny.rr.com> - 2011-11-26 13:42 -0800
  Re: tkinter Jason Swails <jason.swails@gmail.com> - 2011-11-26 18:10 -0500

csiph-web