From 36ca1ff59034dbab237c4fcf7f72acb5510e2523 Mon Sep 17 00:00:00 2001 From: Kevin Matz Date: Sat, 16 Nov 2019 16:21:57 -0500 Subject: [PATCH] lamda closures to set path value at time of creation, not evaluation --- buttond.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buttond.py b/buttond.py index 57d0023..7afa2ee 100755 --- a/buttond.py +++ b/buttond.py @@ -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