Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.064 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.01; 'subject:code': 0.07; 'contexts': 0.09; 'executed': 0.09; 'explanation': 0.09; 'cc:addr :python-list': 0.11; 'subject: \n ': 0.16; 'subject:variable': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'bit': 0.19; 'cc:addr:python.org': 0.22; "shouldn't": 0.24; 'sorry,': 0.24; 'cc:2**0': 0.24; '(see': 0.26; 'right.': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'comments': 0.31; 'problem': 0.35; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'programming,': 0.36; "i'll": 0.36; 'being': 0.38; 'called': 0.40; 'new': 0.61; 'matter': 0.61; 'john': 0.61; "you're": 0.61; 'within': 0.65; 'subject:this': 0.83; 'is)': 0.84; 'subject:before': 0.84; 'to:addr:gordon': 0.84; 'tricky': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=i7ygN32qmfULIaXkwnH8aUmIcRztUcHkmfUa1UXgKgo=; b=gxfLTTzm2LG5oRPZYOmuz7+cXLXBqxT8q0WNMcCA8QWqpPkZfqfYIBVUbRkPs2nQKh 0hXHu7uqHCzz9jokeBbCV0zbMl/Je01vTliDFphIkuDx3wdj4kV/j6f6huLLIkFKFm9S 10BK8SdgRVEeVeLqMkLilQ2Ct0UTGoM77QI6aw4Cx3ukxhX2pVQheDRMzPJ9PvPr3ePx SX3V0+w6k4gq6LpgHMU+g4f5TlNjn+LGsYEaF65xetQgr2Fe0dRLtDf0a0mkE16N7u6e 5dErtJKTqeOXfAuP6an4BIYhuJ8rTe68rvRv6qyDkOKUAPX32+RlwpbIcF03zWvWEmHj VQ/g== X-Received: by 10.152.120.228 with SMTP id lf4mr12321201lab.65.1372106040230; Mon, 24 Jun 2013 13:34:00 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Joshua Landau Date: Mon, 24 Jun 2013 21:33:19 +0100 Subject: Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment) To: John Gordon Content-Type: text/plain; charset=UTF-8 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372106041 news.xs4all.nl 15992 [2001:888:2000:d::a6]:51772 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49078 On 24 June 2013 21:12, John Gordon wrote: > Since you're new to programming, this might be a bit tricky to explain, > but I'll do my best. :-) > > 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. Sorry, but I don't think you're right. Functions "carry" their contexts around with them, so that shouldn't matter (See Peter and Antoon's comments for explanation of what I think it is)