From 984cb23d5630fb05320b418862574209c0308034 Mon Sep 17 00:00:00 2001 From: samypr100 <3933065+samypr100@users.noreply.github.com> Date: Thu, 22 Aug 2024 20:44:37 -0400 Subject: [PATCH] docs: add uv run docs for gui scripts (#6478) ## Summary Follow up docs to https://github.com/astral-sh/uv/pull/6453 --- CONTRIBUTING.md | 4 +- docs/assets/uv_gui_script_hello_world.png | Bin 0 -> 4001 bytes .../assets/uv_gui_script_hello_world_pyqt.png | Bin 0 -> 2280 bytes docs/guides/scripts.md | 48 ++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 docs/assets/uv_gui_script_hello_world.png create mode 100644 docs/assets/uv_gui_script_hello_world_pyqt.png diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af26cb54304d..96285ed14442 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/docs/assets/uv_gui_script_hello_world.png b/docs/assets/uv_gui_script_hello_world.png new file mode 100644 index 0000000000000000000000000000000000000000..c9b5f133c1bd4f51819ecffb5cdb0d6bf3fb9e87 GIT binary patch literal 4001 zcmai%c{J4D|Ht2USu#X+A7smtCHuZJ%1+EEB+O)+F!nVjB4Nm$EhK3ugUK@V$p=e$VH8|G2MvU*|l}J@=e@pO15&X?8Xi>?{H-006LqElnK& zfJWx`+LxL3cRe&L`Tl#l@W2uh3ILZS{~0u32ZfdnE<3F=hw{Jyd4CfUI!aG?`%vU{VSkvOf+dVM0UwM&{H7e`)d`BE@>2bbvd}BM=#2r0KL@e-F z%c4sPy!m@f;3B;j8nIX^fi>{sm63qOW{tAp{Z!;Gyuqn<9KIvMRT(9(*6AuwoSD&9 z5*g1A@={p6L|PejRg&;C9L|*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Yh9p0kny~~%X}24q0z!3#PB!Nd27yyJJ|9c-Z&o$b zNArThQcSr63v2wG(29ArtoJ>13kJ_mITm?(B(I%yXVkrxhOddD?+<>2wZ9Qm<)59yJ{;9$t{p!fv-m^dtg0{+C^A(l%CLIY^AZL- zYo6cFHmA|zWbgloTTG@EV9~7id|?Im@slrGi|q4Ssk^C-EU%KuA(jZMm*LlJTXQmf zbCeUH{eqfLAQm(rKufEnNT4KVn$73hbu82>6h`5v+!h1)8mj+-D^t0%|H4ExtZ0?B zOYZAa-*AeNV#a8lb8KNELrU5>9{Hh$0FRHEp literal 0 HcmV?d00001 diff --git a/docs/assets/uv_gui_script_hello_world_pyqt.png b/docs/assets/uv_gui_script_hello_world_pyqt.png new file mode 100644 index 0000000000000000000000000000000000000000..afe5d78415cf25007283bb536256a918aa367710 GIT binary patch literal 2280 zcmcImSya;d7XDj$G{Z`B$f3H9b#O>?qD<+ih@fE*N@8kuou}gvnnGsXuBnx!Mix$8 zyoqLx;fQ8xX3iCf=7d^GqDZJYfpO?Qorkm5eYy8xPwV&X^{xG|zx_))i-If2Ysdot zpn!08!~lSlmLw<0?U4BW8r_+auq(>hGZp|;^?#Za0;Bg00OTkL$KSA5@^}+&uA1}e zT>?(NI??QP8^fJZgNp!vey&2dRUSd_eD8z5alRe{(Zl@iF%-}d@Y!XL^NC{nP?IXP zn!IrbvD_Ynq2hyvE(JqR1FjzoxpUEvfsTVc)Rxz-wlybKRd>CyGM}qHIJJ)6W13`} zgb)Szv_jIp3Ad#IlCn;sXd}9eCKcrDT(?o$EG9c5mD&{C!jSfKAO%Fcl& zN8Ad=TXG<8J3v3?hOeKV`dbhHF$#wf)_th!xWgmRd22VTo{aGyoK`33RuOe15t8iC zzw~0)raw0Bd%3;GFRb+rTB&jv#*qHD? zy=22@aRk}vaF-TlS>7txr!r>w=E9d4!n&O}8ICz{|tK55Z)N=obKPcCfS zxuV-TLUaVbSx2W5CrI@Eot~C6H!xQg#E$$uaxvH~p3dt-brKs}L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3*=&d|oVyFw@pjonH3(`@Cj! z`T!51@B~~?@=>IJy6oF_bGV`^h%ju2`?Rs_?vp0zqA)_P5>CX^E|xH^_^+Qr4S1e> z%&1StF_vZ7e8cO1ehW6T6!fyG8P>iR^GnxfkrI9D-eBsO(MnT9%}{YCO@)O6v-20 zk0Ak(6{%lz%L$7wDD*YSkV|Qbg{L#-2L?jom;aHivStZTs)RXXxeXUa!o3PJhQ@yw z9&EL{nsBNVMZ)m9H9>@P#}B#TO>DgVEYKp%IQ}9`&rVP^z9$?VGfY0`^%3 zx!6MD_-)cER&vD1e};)q)%lYKA?_0tUFtZq0GaegQ%eI~y2z=K@Y-(w+e*#2SugM2 zMVEtXx}qd;$F03ywhGC*GkuTEZ*4>%fyyI)T8h88#s92;x(t!%RHtZdvl%LfeZ S8(GQM1wg=1jurM7Z~Ost#6i9Q literal 0 HcmV?d00001 diff --git a/docs/guides/scripts.md b/docs/guides/scripts.md index 3ab513df7ea5..5904ac398134 100644 --- a/docs/guides/scripts.md +++ b/docs/guides/scripts.md @@ -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).