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

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

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 (which

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

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

2013-06-24 Thread John Gordon
In b3d3518a-f24a-4c32-a41a-b99145753...@googlegroups.com 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 =

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 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 Joshua Landau
On 24 June 2013 21:12, John Gordon gor...@panix.com 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

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, pablobarhamal...@gmail.com 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,

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 b3d3518a-f24a-4c32-a41a-b99145753...@googlegroups.com 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,

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

2013-06-24 Thread John Gordon
In mailman.3767.1372106609.3114.python-l...@python.org Dave Angel da...@davea.name 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