More importantly: I don't want the variable select to exist globally. It should only be defined within main(). Is there no way to pull this off?
On Monday, February 24, 2014 1:42:18 AM UTC+2, swiftcoder wrote: > > On Sun, Feb 23, 2014 at 4:24 PM, Henré Botha <[email protected]<javascript:> > > wrote: > >> Hi folks, noobie here. Just started playing with pyglet two nights ago. >> Adoring it. >> >> I'm struggling a little with event handlers, and how/where to use them in >> actual code (as opposed to didactic examples). >> >> The problem I am experiencing is inside a function definition: >> initialising a variable before the event handler bit, and then referencing >> said variable inside the event handler, causes an UnboundLocalError >> exception ("local variable 'select' referenced before assignment"). >> >> Why doesn't this work? C-C-C-CODE EXAMPLE: http://pastebin.com/5VYYp8ay >> >> Any help appreciated. :) >> >> > You need to place a 'global settings' statement inside you event handler, > to inform Python that you want to assign to the variable in the outer > scope, rather than creating a new variable in the inner scope. > > -- > Tristam MacDonald > Software Development Engineer, Amazon.com > http://swiftcoder.wordpress.com/ > -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pyglet-users. For more options, visit https://groups.google.com/groups/opt_out.
