Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment) Date: Mon, 24 Jun 2013 21:41:54 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 22 Message-ID: References: NNTP-Posting-Host: panix1.panix.com X-Trace: reader2.panix.com 1372110114 21564 166.84.1.1 (24 Jun 2013 21:41:54 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 24 Jun 2013 21:41:54 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:49090 In Dave Angel writes: > > The problem is that change() isn't being executed here; instead it's being > > executed from within root.mainloop(), whenever the user presses button-1. > > > > And within root.mainloop(), there is no variable called isWhite. > > > Actually that's irrelevant. Whether or not there's one global with the > same name, or twenty-three object attributes with the same name, the > fact that there's a binding of the local makes that name a local. The > only way to avoid that is not to bind, or to use global or nonlocal > declarations. Quite right. I should have verified my answer before posting. Thanks for setting me straight. :-) -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"