1
0
Fork 0

lamda closures to set path value at time of creation, not evaluation

This commit is contained in:
Kevin Matz 2019-11-16 16:21:57 -05:00
parent 5799184fa6
commit 36ca1ff590
1 changed files with 2 additions and 2 deletions

View File

@ -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