Skip to main content

tkwry

License: MIT PyPI - Python Version GitHub Release PyPI Version Downloads Status: Alpha CI codecov

Keep Tkinter — give it the WebView it never had.

Embed a real system WebView (wry) inside your Frame: modern HTML, JS, and IPC in the same layout as your buttons and tabs — one mainloop, no floating overlay.

Alpha — Early preview (see PyPI badge for the current version). APIs and behavior may change without notice. Not recommended for production use yet. Prefer the Python WebView / WebSession API; tkwry._core and .native are Internal (no SemVer) — see Usage — API stability.


📖 Overview

Tkinter is still a solid GUI shell — it just had no first-class way to host modern web content inside a widget. Overlay-style WebViews drift out of sync when you move, resize, or switch tabs.

tkwry fills that missing piece:

  • True child embedding — build_as_child via HWND, NSView, or X11 window ID
  • One event loop — Tk mainloop only; no separate app runtime
  • Local apps — app= serves HTML/CSS/JS without a localhost HTTP server (tkwry:// on macOS/Linux; Windows defaults to https://tkwry.localhost)
  • IPC / RPC / emit — JS↔Python events, request/response, and streams without freezing the UI
  • Trust boundaries — IPC/RPC default to the initial origin; untrusted=True for arbitrary sites
  • Layout-aware — tracks pack / grid / place, tabs, and PanedWindow

💡 Why child-window embedding?

Tkinter apps already have a window and a layout. The web belongs inside a Frame — same mainloop, same tabs and panes — not in a separate top-level webview that floats beside your UI. tkwry wraps wry's build_as_child against the native surface Tk gives your widgets.


🌐 Platform notes

Pre-built abi3 wheels: Windows and macOS. Linux is source-only (best-effort by design).

OS Arch Parent handle Engine
Windows x86_64, arm64 Frame.winfo_id() → HWND WebView2
macOS arm64, x86_64 Toplevel content NSView WKWebView
Linux — winfo_id() → X11 window ID WebKitGTK

DPI, WebView2, macOS embedding / import order, and Linux eval caveats: Platform notes.


🔧 Requirements

  • Python 3.10+
  • Tkinter (included with most Python builds)
  • Building from source (git clone, pip install git+…, or Linux) — Rust toolchain (stable); pip uses maturin as the build backend
  • Windows (x86_64, arm64) — WebView2 Runtime (no fallback engine; see Platform notes)
  • macOS — 11 (Big Sur)+, arm64 or x86_64; system WKWebView
  • Linux — WebKitGTK 4.1 + GTK 3; X11 or XWayland ($DISPLAY); source build only (see Installation and Platform notes)

📦 Installation

PyPI (recommended — Windows / macOS wheels)

pip install tkwry

From a git clone (source build)

Cloning the repo and installing locally compiles the Rust extension on your machine. You need a Rust toolchain (rustup) and platform runtimes from Requirements above (WebView2 on Windows, etc.). pip pulls in maturin automatically as the build backend.

git clone https://github.com/mashu3/tkwry.git
cd tkwry
pip install -e .

Use this for development and for running the examples from the tree.

Install a git revision with pip (source build)

pip install git+https://github.com/mashu3/tkwry.git

This builds from source (sdist via git), not a pre-built wheel — needs Rust, same as pip install .. Prefer the PyPI wheel on Windows and macOS unless you need unreleased commits.

Linux (source install)

Install system dependencies, then build from source (support posture: Platform notes):

# Debian / Ubuntu
sudo apt install \
  libwebkit2gtk-4.1-dev \
  libgtk-3-dev \
  libglib2.0-dev

# Runtime (for end users of your app)
# sudo apt install libwebkit2gtk-4.1-0 libgtk-3-0

pip install maturin
git clone https://github.com/mashu3/tkwry.git
cd tkwry
pip install .

GTK events are pumped automatically on a Tk timer while your app runs.


🚀 Usage

Basic WebView

import tkinter as tk
from tkwry import WebView

root = tk.Tk()
root.geometry("900x600")

frame = tk.Frame(root, bg="#222")
frame.pack(fill="both", expand=True, padx=8, pady=8)

web = WebView(frame, url="https://github.com")
web.when_failed(lambda exc: print("native create failed:", exc))

root.mainloop()

The constructor does not raise if native create fails. Handle when_failed / <<WebViewCreateFailed>>. Minimal app, app=, hidden hosts, User-Agent, downloads, cleanup, and the API table: Usage (Minimal app). IPC / RPC / stream: docs/rpc.md. Trust (untrusted, bridge_origins): docs/trust.md.


🧩 Features

Embedding & layout

  • Native child of your Tk surface (build_as_child) — not a floating overlay
  • Bounds / visibility follow <Configure>, <Map>, <Unmap> (Notebook tabs hide unmapped views)
  • Works with pack / grid / place, Notebook, and PanedWindow; window chrome is the host Toplevel (Layout / resize)

Local apps & bridge

  • app= serves assets without a localhost HTTP server (tkwry:// on macOS/Linux; Windows defaults to https://tkwry.localhost)
  • IPC / RPC / emit between JS and Python (docs/rpc.md)
  • Origin-scoped bridge by default; untrusted= for arbitrary sites (docs/trust.md)

Browser-ish APIs

  • WebSession / profiles, cookies (Usage — Shared session); navigation hooks, downloads, print, DevTools (platforms)
  • Native file drag & drop into the WebView area (notify-only)

Host integration

  • Typed create / eval / navigation / download failure signals on the Tk thread
  • Lifecycle callbacks deferred onto Tk (avoids native-thread deadlocks)
  • tkwry.testing wait helpers for integration tests

Plotly / Folium / Markdown demos live under Examples. Prefer tkwry_browser.py as the full-layout sample (docs/examples-browser.md).


📁 Examples

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e .

Start here: mini-browser

The easiest way to see tkwry in a full layout: toolbar + side pane + content tabs, all as child WebViews.

macOS · dark Windows · light
tkwry browser on macOS (dark) tkwry browser on Windows (light)
Script Description
examples/tkwry_browser.py Flagship mini-browser (single file): app= toolbar / side / Settings, separate content WebSession, New Tab start page, profiles, shortcuts
python examples/tkwry_browser.py
python examples/tkwry_browser.py --private

Architecture, trust split, and what to copy: docs/examples-browser.md.

Focused demos

Script Description
examples/ipc_demo.py IPC events, RPC (call / kwargs / worker), stream (ticks + cancel), and emit
examples/multi_demo.py Multiple WebViews, tabs, panes; emit_all flash
examples/plotly_demo.py Plotly charts — CDN or local app= (pip install plotly)
examples/folium_demo.py Folium maps (pip install folium; tiles need the network)
examples/markdown_demo.py Monaco markdown editor + live preview (CDN)
examples/dnd_demo.py Native file drag & drop into WebView
python examples/ipc_demo.py
python examples/multi_demo.py
python examples/plotly_demo.py
python examples/folium_demo.py
python examples/markdown_demo.py
python examples/dnd_demo.py

Related: Jupyter-style widgets (tkipw)

Built on tkwry. Use when you want the usual ipywidgets / anywidget stack in Tk (not plain HTML + JS):

Script Description
plotly_demo.py Plotly FigureWidget
ipyleaflet_demo.py Live ipyleaflet map

See the tkipw examples for more.


⚠️ Known limitations

Short checklist — details live in Platform notes (especially macOS embedding).

Platforms

  • Windows — WebView2 Runtime required; missing → create-failed signals (install notes)
  • Linux — no PyPI wheel (by design); best-effort source install; prefer sequential eval_js_with_callback across multiple views (Linux)

Engine gaps / partial wraps (no invented shims)

  • Print — system dialog (print(); macOS also print_with_options for margins); no PDF / no result (Print)
  • Downloads — start-deny only; no mid-flight abort, pause/resume, or progress % (Downloads)
  • Cookies / browsing data — Cookie CRUD + clear_all_browsing_data() (WebView wipe-all); no dedicated localStorage / cache / IndexedDB Python APIs and no selective clear (Cookies / browsing data)
  • Screenshot / find in page — not exposed as tkwry APIs (Windows may still show engine Ctrl+F chrome) (Screenshot, Find)

macOS / Windows quirks

  • macOS — import tkwry before AppKit; inline url() may be None; DevTools needs devtools=True then open_devtools() (private APIs — avoid Mac App Store) (macOS embedding, DevTools)
  • Windows DevTools — open_devtools() works; close_devtools is a no-op; is_devtools_open always False (DevTools)

Trust & session

  • Shared WebSession + app= must use the same root and matching serve options (including https_scheme); do not share a persistent profile with untrusted sites
  • External content / IPC defaults and untrusted= — Trust boundaries

Lifecycle & IPC

  • Sync on_navigation / on_new_window / on_download / create-time permission_handler may block the engine until they return (wait capped ~60s); do not create a WebView from on_new_window (lifecycle callbacks)
  • RPC cancel / destroy() are cooperative only; async queues cap at 2048 each; IPC/RPC messages at 10 MiB (RPC limits, timeout/cancel)
  • Eval / navigation timeouts surface typed events/errors on the Tk thread (not raised on the WebKit thread)
  • Native drag & drop is WebView area only and notify-only (cannot deny from Python; use tkinterdnd2 for arbitrary Tk widgets)

See CHANGELOG.md for release history.


🗂 Documentation

Topic Doc
Usage (minimal app, app=, hidden hosts, UA, API) docs/usage.md
Mini-browser example (flagship layout / sessions / trust) docs/examples-browser.md
Trust boundaries (untrusted, bridge_origins, recipes) docs/trust.md
IPC / RPC / emit (expose, call / stream, cancel, limits) docs/rpc.md
Platform notes (Windows / macOS / Linux, print, window chrome) docs/platforms.md
wry embedding / API ownership map docs/wry-embedding.md
Packaging (PyInstaller / Nuitka → .exe / .app) docs/packaging.md

📝 License

This project is licensed under the MIT License. See LICENSE.

This project links against wry, which is dual-licensed (Apache-2.0 or MIT). tkwry uses wry under MIT; see NOTICE for attribution.


👨‍💻 Author

mashu3

Contributors

Metadata

Release files for tkwry 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tkwry 0.1.9
File Size Uploaded
tkwry-0.1.9.tar.gz 1.0 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for tkwry 0.1.9
File
tkwry-0.1.9-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
tkwry-0.1.9-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
tkwry-0.1.9-cp310-abi3-macosx_11_0_x86_64.whl CPython 3.10 abi3 macOS 11.0+ x86-64 Details
tkwry-0.1.9-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details

Total release size: 3.9 MB

Release files / tkwry-0.1.9.tar.gz

Download URL tkwry-0.1.9.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
f0616faf076ce736709a52aaaea15e770252c4c0337a63b3c06204fd27edb13a
BLAKE2b-256 checksum
How to use checksums
1bb3a61aa872a31282309218b28abc5a5d1153544c1f09b545361a35a3581361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / tkwry-0.1.9-cp310-abi3-win_arm64.whl

Download URL tkwry-0.1.9-cp310-abi3-win_arm64.whl
Size 602.0 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
7bd6faf55c51d9014f4bc8e82e9455b04ebe264d4d98441da0bc6bbc41517a2d
BLAKE2b-256 checksum
How to use checksums
64085d89ebdd0444c852b38c26a973de0ccef0bbaf2718a4c4a9c29722d641e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / tkwry-0.1.9-cp310-abi3-win_amd64.whl

Download URL tkwry-0.1.9-cp310-abi3-win_amd64.whl
Size 623.8 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4874a6f778d473feb4aed3f68caab52446e0e2c7b376514a98d4510b49ecb390
BLAKE2b-256 checksum
How to use checksums
8d923c6d5289373b70c4f4234c13e851f2275a985c2db93e255e34882fc08a4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / tkwry-0.1.9-cp310-abi3-macosx_11_0_x86_64.whl

Download URL tkwry-0.1.9-cp310-abi3-macosx_11_0_x86_64.whl
Size 828.6 kB
Tags CPython 3.10 abi3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
b2d17aa10857e4bf1f3ea9266a11e81b89d91108a2a8e81189fabebaabd7fb4b
BLAKE2b-256 checksum
How to use checksums
4d3040e4cfb614ec4bcb5d5d3daf5984dff15716db8f7f457201475dd88b49bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / tkwry-0.1.9-cp310-abi3-macosx_11_0_arm64.whl

Download URL tkwry-0.1.9-cp310-abi3-macosx_11_0_arm64.whl
Size 793.3 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ce9dacdb62095d81c4754ffcc2b031540b3438180c89a7242b1e8da66a3f2b9a
BLAKE2b-256 checksum
How to use checksums
ca8553abc4003c511843efef902be1365be2fbaeb354020a822215038f31b990
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.9 This release

5 release files

0.1.8

5 release files

0.1.7

5 release files

0.1.6

5 release files

0.1.5

5 release files

0.1.4

5 release files

0.1.3

5 release files

0.1.2

5 release files

0.1.1

5 release files

0.1.0

5 release files

0.0.9

5 release files

0.0.8

5 release files

0.0.7

5 release files

0.0.6

5 release files

0.0.5

4 release files

0.0.4

4 release files

0.0.3

4 release files

0.0.2

4 release files

0.0.1

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page