Skip to content

Commit cb5ac8d

Browse files
committed
fix put_buttons() issue when buttons have same value
reproduce code: ``` put_buttons([ {'label': 'A', 'value': 1}, {'label': 'B', 'value': 1}, ], [lambda: put_text('A'), lambda: put_text('B')]) ```
1 parent 81d57ba commit cb5ac8d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pywebio/output.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
208208
209209
"""
210+
import copy
210211
import html
211212
import io
212213
import logging
@@ -670,6 +671,7 @@ def _format_button(buttons):
670671

671672
btns = []
672673
for btn in buttons:
674+
btn = copy.deepcopy(btn)
673675
if isinstance(btn, Mapping):
674676
assert 'value' in btn and 'label' in btn, 'actions item must have value and label key'
675677
elif isinstance(btn, (list, tuple)):
@@ -763,10 +765,11 @@ def delete():
763765

764766
if isinstance(onclick, Sequence):
765767
assert len(btns) == len(onclick), "`onclick` and `buttons` must be same length."
766-
onclick = {btn['value']: callback for btn, callback in zip(btns, onclick)}
768+
for idx, btn in enumerate(btns):
769+
btn['value'] = idx
767770

768771
def click_callback(btn_val):
769-
if isinstance(onclick, dict):
772+
if isinstance(onclick, Sequence):
770773
return onclick[btn_val]()
771774
else:
772775
return onclick(btn_val)

0 commit comments

Comments
 (0)