Changing global variables in tkinter/pmw callback
Brian Elmegaard
be at mek.dtu.dk
Thu Apr 5 03:41:51 EDT 2001
Hi,
I think I am running into a problem with scope, but I am not sure.
I have a global variable CurrentCanvasSetting. This is set to first set
to 'init'.
I then have two class instances, one for a toolbar and one for a canvas.
In the in __init__ of the toolbar I set the callback of the buttons as:
button.configure(command = lambda self=self,
button=button, buttons=self.buttons,
setting=CurrentCanvasSetting:
self.apply(button,buttons,setting))
In apply I do:
def apply(self,button,buttons,setting):
setting= button.cget('text')
and in here I can then print setting and see it holds the name of the
button.
However, this is not passed to the global CurrentCanvasSetting as seen
when I try to use it in the sheet class:
self.sc.component('canvas').bind('<1>', lambda event,
self=self,
setting=CurrentCanvasSetting:
self.addit(setting,event))
where addit is:
def addit(self,setting,event):
print setting
but always prints 'init'.
How can I change CurrentCanvasSetting from toolbar.apply and make
sheet.addit see the change?
--
Brian
http://www.et.dtu.dk/energysystems
http://www.rk-speed.dk http://fiduso.dk http://sunsite.auc.dk/dk-tug
\TeX, tak
More information about the Python-list
mailing list