lamda closures to set path value at time of creation, not evaluation
This commit is contained in:
parent
5799184fa6
commit
36ca1ff590
|
@ -54,8 +54,8 @@ for b in config.get('button', 'names').split(','):
|
|||
print('init button on GPIO', p)
|
||||
_buttons[b] = Button(p)
|
||||
# connect button callbacks to anonymous functions
|
||||
_buttons[b].when_pressed = lambda: activate(closed)
|
||||
_buttons[b].when_released = lambda: activate(opened)
|
||||
_buttons[b].when_pressed = lambda path=closed: activate(path)
|
||||
_buttons[b].when_released = lambda path=opened: activate(path)
|
||||
except (KeyError, GPIODeviceError) as e:
|
||||
print('Error configuring button', b, e)
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue