Native GUI apps in Rust. Your crate compiles to a WebAssembly module, and ztk runs it in a native window on macOS, Windows, and Linux. The widgets are the widgets of Tk: labels, buttons, entries, a canvas, a text widget, and the rest.
pub use tk::app_event;
use tk::{Button, Entry, Label, Pack};
#[no_mangle]
pub extern "C" fn app_init() {
let root = tk::root().title("Hello from Rust");
let msg = Label::new(root).text("Type a name.");
let name = Entry::new(root).width(24);
let greet = Button::new(root).text("Greet").on_click(move || {
msg.text(&format!("Hello, {}, from Rust!", name.get()));
});
let pad = Pack { padx: 16, pady: 8, ..Pack::default() };
msg.pack(pad);
name.pack(pad);
greet.pack(pad);
}cargo build --release --target wasm32-unknown-unknown
ztk target/wasm32-unknown-unknown/release/hello.wasmThe module of this app has 21,037 bytes.
ztk has a WebAssembly interface with the name tk: 91 typed functions for the widgets, the options, the geometry, the canvas, the events, and the timers. A widget is a handle, an option is a case of an enum, and a number goes as a number. No Tcl text crosses the boundary. This crate puts these functions in the form of Rust: one Copy type for each widget class, setters that chain, and closures as callbacks. The crate has no dependency.
- The API: each type and each method.
- From Rust to a program file: build a module, run it, test it, and bundle it as one app.
- The interface and its ABI, in the ztk repository.
- Apps in other languages: the same interface has bindings for Go (ztk-go) and more.
- Rust with the target
wasm32-unknown-unknown:rustup target add wasm32-unknown-unknown. - ztk with
ztk::wasm::run(the command of ztk#429).
The crate is not on crates.io yet. Use the repository:
[lib]
crate-type = ["cdylib"]
[dependencies]
tk = { package = "ztk", git = "https://github.com/beetlebugorg/ztk-rust" }
[profile.release]
opt-level = "s"
lto = true
panic = "abort"
codegen-units = 1
strip = trueAn app exports app_init, which builds the widgets, and exports app_event of the crate again with pub use tk::app_event;. That export runs your closures.
| Example | What it shows | Module |
|---|---|---|
| hello | A label, an entry, and a button | 21,037 bytes |
| sheet | A spreadsheet with formulas, on a canvas with an entry | 72,844 bytes |
| vector | A drawing app: shapes, a selection, a drag | 25,694 bytes |
| gallery | Each widget class, the variables, the fonts, the timers, a second window | 53,833 bytes |
| escape | Text with each special character of Tcl, as plain text | 20,539 bytes |
make # builds dist/hello.wasm and the others
make run APP=sheet # runs one in a window
make test # runs each example headless with its checksmake test runs the check scripts of tests/: each one drives its app with pointer and key events and reads the widgets. The five examples have 78 checks.
![]() |
![]() |
src/raw.rs has the imports, the enums, and one safe function for each import. The tool tools/wasm-tk-gen.py of ztk writes it from tk.wit, so the file changes only with the interface. src/lib.rs is the part written by hand.
MIT. See LICENSE.


