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
-- 
http://mail.python.org/mailman/listinfo/python-list
  • tkinter Dave
    • Re: tkinter Jason Swails

Reply via email to