Apps in Rust, Go, or JavaScript
Write the app in Rust, Go, or JavaScript, and get a native ztk window. The program compiles to WebAssembly, and ztk gives it the Tk API as typed imports.

How it works
The Tk API is a WebAssembly interface with 91 functions, in the file src/library/wasm/tk.wit. Each language has a binding that puts this API in the form of the language. No Tcl text crosses the boundary.
This is the hello app in Rust (the binding):
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.").id("msg");
let name = Entry::new(root).width(24).id("name");
let greet = Button::new(root).text("Greet").id("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.wasm
A module has only its linear memory and the imports of tk. It gets no file, socket, or process of its own. ztk https://... runs a module from a URL in a sandbox with no capability and a memory limit of 1 GiB. ztk bundle makes one program file from a module.
Real today
The bindings for Rust, Go, and JavaScript are in their own repositories. Each binding has four examples: a hello app, a spreadsheet with formulas, a vector drawing app, and a test of special characters.
Links
- Rust, Go, or JavaScript: set up a project, build, test, and bundle.
- ztk-rust, ztk-go, and ztk-wasm-demos: the bindings and the examples.
- ztk::wasm::run: run a module from a Tcl script.