---
jupytext:
  text_representation:
    extension: .md
    format_name: myst
    format_version: 0.13
kernelspec:
  display_name: SageMath 10.4
  language: sage
  name: sagemath
---

# Un exemple de mini applet: le pivot de Gauß

```{code-cell} ipython3
%display latex
```

```{code-cell} ipython3
import ipywidgets
```

```{code-cell} ipython3
M = random_matrix(QQ, 5, 7)
```

```{code-cell} ipython3
M
```

```{code-cell} ipython3
rowIndices = list(range(M.nrows()))
```

```{code-cell} ipython3
rowIndices
```

```{code-cell} ipython3
L1 = ipywidgets.Dropdown(description="L1", options=rowIndices)
L2 = ipywidgets.Dropdown(description="L2", options=rowIndices)
```

```{code-cell} ipython3
L1
```

```{code-cell} ipython3
L1.value
```

```{code-cell} ipython3
Lambda = ipywidgets.Text()
Lambda
```

```{code-cell} ipython3
Lambda.value
```

```{code-cell} ipython3
Echange = ipywidgets.Button(description="Echange"); Echange
```

```{code-cell} ipython3
Matrix = ipywidgets.Output()
```

```{code-cell} ipython3
Matrix
```

```{code-cell} ipython3
def update():
    Matrix.clear_output(wait=True)
    with Matrix:
        display(M)
```

```{code-cell} ipython3
update()
```

```{code-cell} ipython3
App = ipywidgets.VBox([L1, L2, Lambda, Echange, Matrix])
```

```{code-cell} ipython3
App
```

```{code-cell} ipython3
def echange(context):
    l1 = L1.value
    l2 = L2.value
    M[l1], M[l2] = M[l2], M[l1]
    update()
        
```

```{code-cell} ipython3
Echange.on_click(echange)
```

À vous de compléter!
