tkinter

J

Jason Swails

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top