docs: add uv run docs for gui scripts (#6478)

## Summary

Follow up docs to https://github.com/astral-sh/uv/pull/6453
This commit is contained in:
samypr100 2024-08-22 20:44:37 -04:00 committed by GitHub
parent 34dd8401ed
commit 984cb23d56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 50 additions and 2 deletions

View file

@ -137,9 +137,9 @@ To preview any changes to the documentation locally:
1. Install the [Rust toolchain](https://www.rust-lang.org/tools/install).
1. Run `cargo dev generate-all`, to update any auto-generated documentation.
2. Run `cargo dev generate-all`, to update any auto-generated documentation.
1. Run the development server with:
3. Run the development server with:
```shell
# For contributors.

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

@ -212,6 +212,54 @@ $ uv run --python 3.10 example.py
See the [Python version request](../concepts/python-versions.md#requesting-a-version) documentation
for more details on requesting Python versions.
## Using GUI scripts
On Windows `uv` will run your script ending with `.pyw` extension using `pythonw`:
```python title="example.pyw"
from tkinter import Tk, ttk
root = Tk()
root.title("uv")
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Label(frm, text="Hello World").grid(column=0, row=0)
root.mainloop()
```
```console
PS> uv run example.pyw
```
![Run Result](../assets/uv_gui_script_hello_world.png){: style="height:50px;width:150px"}
Similarly, it works with dependencies as well:
```python title="example_pyqt.pyw"
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QGridLayout
app = QApplication(sys.argv)
widget = QWidget()
grid = QGridLayout()
text_label = QLabel()
text_label.setText("Hello World!")
grid.addWidget(text_label)
widget.setLayout(grid)
widget.setGeometry(100, 100, 200, 50)
widget.setWindowTitle("uv")
widget.show()
sys.exit(app.exec_())
```
```console
PS> uv run --with PyQt5 example_pyqt.pyw
```
![Run Result](../assets/uv_gui_script_hello_world_pyqt.png){: style="height:50px;width:150px"}
## Next steps
To learn more about `uv run`, see the [command reference](../reference/cli.md#uv-run).