From d5b5c255e895bcb031ae31c8848362034bdbe054 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Sun, 22 Mar 2026 03:32:02 +0300 Subject: [PATCH] feat: bundle tkinter into Windows portable build Download _tkinter.pyd, tkinter package, and Tcl/Tk DLLs from the official Python nuget package and copy them into the embedded Python directory. This enables the screen overlay visualization during calibration in the portable build. --- build-dist-windows.sh | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/build-dist-windows.sh b/build-dist-windows.sh index 0b68115..abd7c9e 100644 --- a/build-dist-windows.sh +++ b/build-dist-windows.sh @@ -85,6 +85,74 @@ if ! grep -q '\.\./app/src' "$PTH_FILE"; then fi echo " Patched $(basename "$PTH_FILE")" +# ── Bundle tkinter into embedded Python ─────────────────────── +# Embedded Python doesn't include tkinter. We download it from the +# official Windows Python nuget package (same version) which contains +# the _tkinter.pyd, tkinter/ package, and Tcl/Tk DLLs. + +echo "[3b/8] Bundling tkinter for screen overlay support..." + +# Python minor version for nuget package (e.g., 3.11.9 -> 3.11) +PYTHON_MINOR="${PYTHON_VERSION%.*}" + +# Download the full Python nuget package (contains all stdlib + DLLs) +NUGET_URL="https://www.nuget.org/api/v2/package/python/${PYTHON_VERSION}" +NUGET_PKG="$BUILD_DIR/python-nuget.zip" +if [ ! -f "$NUGET_PKG" ]; then + curl -sL "$NUGET_URL" -o "$NUGET_PKG" +fi + +NUGET_DIR="$BUILD_DIR/python-nuget" +rm -rf "$NUGET_DIR" +mkdir -p "$NUGET_DIR" +unzip -qo "$NUGET_PKG" -d "$NUGET_DIR" + +# Copy _tkinter.pyd (the C extension) +TKINTER_PYD=$(find "$NUGET_DIR" -name "_tkinter.pyd" | head -1) +if [ -n "$TKINTER_PYD" ]; then + cp "$TKINTER_PYD" "$PYTHON_DIR/" + echo " Copied _tkinter.pyd" +else + echo " WARNING: _tkinter.pyd not found in nuget package" +fi + +# Copy tkinter Python package from the stdlib zip or Lib/ +# The nuget package has Lib/tkinter/ +TKINTER_PKG=$(find "$NUGET_DIR" -type d -name "tkinter" | head -1) +if [ -n "$TKINTER_PKG" ]; then + mkdir -p "$PYTHON_DIR/Lib" + cp -r "$TKINTER_PKG" "$PYTHON_DIR/Lib/tkinter" + echo " Copied tkinter/ package" +else + echo " WARNING: tkinter package not found in nuget package" +fi + +# Copy Tcl/Tk DLLs (tcl86t.dll, tk86t.dll, etc.) +for dll in tcl86t.dll tk86t.dll; do + DLL_PATH=$(find "$NUGET_DIR" -name "$dll" | head -1) + if [ -n "$DLL_PATH" ]; then + cp "$DLL_PATH" "$PYTHON_DIR/" + echo " Copied $dll" + fi +done + +# Copy Tcl/Tk data directories (tcl8.6, tk8.6) +for tcldir in tcl8.6 tk8.6; do + TCL_PATH=$(find "$NUGET_DIR" -type d -name "$tcldir" | head -1) + if [ -n "$TCL_PATH" ]; then + cp -r "$TCL_PATH" "$PYTHON_DIR/$tcldir" + echo " Copied $tcldir/" + fi +done + +# Add Lib to ._pth so tkinter package is importable +if ! grep -q '^Lib$' "$PTH_FILE"; then + echo 'Lib' >> "$PTH_FILE" +fi + +rm -rf "$NUGET_DIR" +echo " tkinter bundled successfully" + # ── Download pip and install into embedded Python ──────────── echo "[4/8] Installing pip into embedded Python..."