| 1 | [Bug]: using clf and pyplot.draw in range slider on_changed callback blocks input to widgets |
| 2 | ### Bug summary |
| 3 | |
| 4 | When using clear figure, adding new widgets and then redrawing the current figure in the on_changed callback of a range slider the inputs to all the widgets in the figure are blocked. When doing the same in the button callback on_clicked, everything works fine. |
| 5 | |
| 6 | ### Code for reproduction |
| 7 | |
| 8 | ```python |
| 9 | import matplotlib.pyplot as pyplot |
| 10 | import matplotlib.widgets as widgets |
| 11 | |
| 12 | def onchanged(values): |
| 13 | print("on changed") |
| 14 | print(values) |
| 15 | pyplot.clf() |
| 16 | addElements() |
| 17 | pyplot.draw() |
| 18 | |
| 19 | def onclick(e): |
| 20 | print("on click") |
| 21 | pyplot.clf() |
| 22 | addElements() |
| 23 | pyplot.draw() |
| 24 | |
| 25 | def addElements(): |
| 26 | ax = pyplot.axes([0.1, 0.45, 0.8, 0.1]) |
| 27 | global slider |
| 28 | slider = widgets.RangeSlider(ax, "Test", valmin=1, valmax=10, valinit=(1, 10)) |
| 29 | slider.on_changed(onchanged) |
| 30 | ax = pyplot.axes([0.1, 0.30, 0.8, 0.1]) |
| 31 | global button |
| 32 | button = widgets.Button(ax, "Test") |
| 33 | button.on_clicked(onclick) |
| 34 | |
| 35 | addElements() |
| 36 | |
| 37 | pyplot.show() |
| 38 | ``` |
| 39 | |
| 40 | |
| 41 | ### Actual outcome |
| 42 | |
| 43 | The widgets can't receive any input from a mouse click, when redrawing in the on_changed callback of a range Slider. |
| 44 | When using a button, there is no problem. |
| 45 | |
| 46 | ### Expected outcome |
| 47 | |
| 48 | The range slider callback on_changed behaves the same as the button callback on_clicked. |
| 49 | |
| 50 | ### Additional information |
| 51 | |
| 52 | The problem also occurred on Manjaro with: |
| 53 | - Python version: 3.10.9 |
| 54 | - Matplotlib version: 3.6.2 |
| 55 | - Matplotlib backend: QtAgg |
| 56 | - Installation of matplotlib via Linux package manager |
| 57 | |
| 58 | |
| 59 | ### Operating system |
| 60 | |
| 61 | Windows 10 |
| 62 | |
| 63 | ### Matplotlib Version |
| 64 | |
| 65 | 3.6.2 |
| 66 | |
| 67 | ### Matplotlib Backend |
| 68 | |
| 69 | TkAgg |
| 70 | |
| 71 | ### Python version |
| 72 | |
| 73 | 3.11.0 |
| 74 | |
| 75 | ### Jupyter version |
| 76 | |
| 77 | _No response_ |
| 78 | |
| 79 | ### Installation |
| 80 | |
| 81 | pip |