Native GUI apps in Go. Your Go program 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.
package main
import "github.com/beetlebugorg/ztk-go/tk"
//go:wasmexport app_init
func appInit() {
root := tk.Root()
root.SetTitle("Hello from Go")
msg := tk.NewLabel(root, tk.Opts{Text: "Type a name."})
name := tk.NewEntry(root, tk.Opts{Width: 24})
greet := tk.NewButton(root, tk.Opts{Text: "Greet", Command: func() {
msg.SetText("Hello, " + name.Get() + ", from Go!")
}})
pad := tk.Pack{PadX: 16, PadY: 8}
msg.Pack(pad)
name.Pack(pad)
greet.Pack(pad)
}
func main() {}tinygo build -target=wasm-unknown -gc=conservative -opt=z -no-debug -o hello.wasm .
ztk hello.wasmThe module of this app has 7,869 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. The package tk of this repository puts these functions in the form of Go: one type for each widget class, option structs, and Go functions as callbacks.
- The API: each type and each method.
- From Go 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 Rust (
ztk-rust) and more.
- TinyGo 0.44 or later, with
wasm-optof Binaryen on thePATHor inWASMOPT. The standard Go compiler makes a module for WASI or for a browser, with a runtime that this interface does not use. - ztk with
ztk::wasm::run(the command of ztk#429).
go mod init example.com/myapp
go get github.com/beetlebugorg/ztk-goAn app exports app_init, which builds the widgets. The package exports app_event, which runs your callbacks. main stays empty.
| Example | What it shows | Module |
|---|---|---|
| hello | A label, an entry, and a button | 7,869 bytes |
| sheet | A spreadsheet with formulas, on a canvas with an entry | 76,351 bytes |
| vector | A drawing app: shapes, a selection, a drag | 16,342 bytes |
| escape | Text with each special character of Tcl, as plain text | 9,138 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 four examples have 52 checks.
![]() |
![]() |
tk/raw.go has the imports and the enums. The tool tools/wasm-tk-gen.py of ztk writes it from tk.wit, so the file changes only with the interface. tk/tk.go is the part written by hand.
MIT. See LICENSE.


