Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread John Gordon
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

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Dave Angel
On 06/24/2013 04:12 PM, John Gordon wrote: In pablobarhamal...@gmail.com writes: isWhite = True def change(event): if event.x > x1 and event.x < x2 and event.y > y1 and event.y < y2: if isWhite: w.itemconfig(rect, fill="blue") isWhite = False

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Joshua Landau
On 24 June 2013 21:19, wrote: > Thank's to you all! > > Setting isWhite as global worked fine. > I'll probably be back soon with another silly question, see you then :) By the way, it's normally bad to use globals like this. When you're learning it's something you just do, though; it's fine for

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Joshua Landau
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.

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Joshua Landau
Here's a little test to make sure you understand (this is one of the most confusing parts of Python's closures in my opinion): foo = "I'm foo!" def working(): print(foo) def broken(): print(foo) if False: # There's no way this could cause a problem! foo = "This will *never*

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread pablobarhamalzas
Thank's to you all! Setting isWhite as global worked fine. I'll probably be back soon with another silly question, see you then :) -- http://mail.python.org/mailman/listinfo/python-list

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread John Gordon
In pablobarhamal...@gmail.com writes: > isWhite = True > > def change(event): > if event.x > x1 and event.x < x2 and event.y > y1 and event.y < y2: > if isWhite: > w.itemconfig(rect, fill="blue") > isWhite = False > else: > w.itemc

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Antoon Pardon
Op 24-06-13 21:47, pablobarhamal...@gmail.com schreef: Hi there! I'm quite new to programming, even newer in python (this is actually the first thing I try on it), and every other topic I've seen on forums about my problem doesn't seem to help. So, the following lines are intended to draw a wh

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread Peter Otten
pablobarhamal...@gmail.com wrote: > Hi there! I'm quite new to programming, even newer in python (this is > actually the first thing I try on it), and every other topic I've seen on > forums about my problem doesn't seem to help. > > So, the following lines are intended to draw a white square (wh

Re: What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread pablobarhamalzas
Just before anyone says, the reason I bind to the Canvas instead of binding directly to the rectangle is because I plan to add more squares in the future. Cheers. -- http://mail.python.org/mailman/listinfo/python-list

What's wrong with this code? (UnboundLocalError: local variable referenced before assignment)

2013-06-24 Thread pablobarhamalzas
Hi there! I'm quite new to programming, even newer in python (this is actually the first thing I try on it), and every other topic I've seen on forums about my problem doesn't seem to help. So, the following lines are intended to draw a white square (which it does), turn it to blue when you cl

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread danieldelay
Le 08/06/2010 10:03, ch1zra a écrit : import os, time, re, pyodbc, Image, sys from datetime import datetime, date, time from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm from reportlab.pdfgen import canvas from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttf

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Bruno Desthuilliers
ch1zra a écrit : On Jun 8, 10:59 am, Bryan wrote: Python doesn't have one global namespace. Each module (file) has its own namespace, which is a Python dict, and 'global' means defined in the containing module's dict. Put the import: from reportlab.pdfgen import canvas in the mkTable.py fil

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Bryan
Peter Otten wrote: > Chris Rebert wrote: [...] > > The only global variable defined in mkTable.py is the "mkTable" > > function (partly since you don't import anything). So the reference to > > the global variable "canvas" on the right-hand side of this expression > > is completely undefined, resul

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Peter Otten
Chris Rebert wrote: > On Tue, Jun 8, 2010 at 2:00 AM, ch1zra wrote: >> On Jun 8, 10:29 am, Richard Thomas wrote: >>> On Jun 8, 9:03 am, ch1zra wrote: >>> > I have following code : >>> >>> > import os, time, re, pyodbc, Image, sys >>> > from datetime import datetime, date, time >>> > from report

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
On Jun 8, 10:59 am, Bryan wrote: > ch1zra wrote: > > I have following code : > > > import os, time, re, pyodbc, Image, sys > > from datetime import datetime, date, time > > from reportlab.lib.pagesizes import A4 > > from reportlab.lib.units import cm > > from reportlab.pdfgen import canvas > > fro

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Chris Rebert
On Tue, Jun 8, 2010 at 2:00 AM, ch1zra wrote: > On Jun 8, 10:29 am, Richard Thomas wrote: >> On Jun 8, 9:03 am, ch1zra wrote: >> > I have following code : >> >> > import os, time, re, pyodbc, Image, sys >> > from datetime import datetime, date, time >> > from reportlab.lib.pagesizes import A4 >>

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
On Jun 8, 10:29 am, Richard Thomas wrote: > On Jun 8, 9:03 am, ch1zra wrote: > > > > > > > I have following code : > > > import os, time, re, pyodbc, Image, sys > > from datetime import datetime, date, time > > from reportlab.lib.pagesizes import A4 > > from reportlab.lib.units import cm > > from

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Bryan
ch1zra wrote: > I have following code : > > import os, time, re, pyodbc, Image, sys > from datetime import datetime, date, time > from reportlab.lib.pagesizes import A4 > from reportlab.lib.units import cm > from reportlab.pdfgen import canvas > from reportlab.pdfbase import pdfmetrics > from repor

Re: UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread Richard Thomas
On Jun 8, 9:03 am, ch1zra wrote: > I have following code : > > import os, time, re, pyodbc, Image, sys > from datetime import datetime, date, time > from reportlab.lib.pagesizes import A4 > from reportlab.lib.units import cm > from reportlab.pdfgen import canvas > from reportlab.pdfbase import pdf

UnboundLocalError: local variable referenced before assignment

2010-06-08 Thread ch1zra
I have following code : import os, time, re, pyodbc, Image, sys from datetime import datetime, date, time from reportlab.lib.pagesizes import A4 from reportlab.lib.units import cm from reportlab.pdfgen import canvas from reportlab.pdfbase import pdfmetrics from reportlab.pdfbase.ttfonts import TTF