gui

Desktop windows: buttons, text boxes, tables, menus and dialogs. Make a window with gui.window(title), add widgets to it top to bottom (win.label("Hi"), win.button("Go", fn() { ... })), put widgets side by side in win.row(), then call win.run() to show it. Light and dark themes in TB's colours. Needs the TB app on a computer (not the browser playground).

This library opens real windows, so it needs the TB app on your computer. The examples here show the code; run them with tb file.tb.

import gui

Example

Needs the TB app on your computer, so there is no Run button here.

import gui

let win = gui.window("Hello", {"width": 360, "height": 200})
win.label("What's your name?")
let box = win.input({"placeholder": "Type here"})
win.button("Say hello", fn() {
  gui.alert(f"Hello, {box.value}!")
})
win.run()

Functions

window(title, options?)

returns window

Make a window. options: width, height (pixels; default 520 x 400), theme ("light" or "dark"), resizable. Add widgets to it, then call win.run() to show it. Add widgets to a window, a row() or a column() (they stack top to bottom; a row puts them side by side): label(text, options?) options: style ("normal", "title", "heading", "bold", "muted", "accent", "small", "display", "success", "danger", "mono"), wrap (pixels), align ("left", "center", "right"), width (characters) button(text, on_click?, options?) options: primary (true for the main button), width, expand input(options?) options: placeholder, value, on_enter(text), on_change(text), secret, width, expand textarea(options?) options: value, on_change(text), height (lines), mono, wrap, readonly, expand checkbox(text, options?) options: checked, on_change(checked) select(choices, options?) options: value, on_change(choice), width, expand table(columns, options?) options: height (rows), widths, on_select(row, index), on_open(row, index), expand list_box(items?, options?) options: height, on_select(item, index), on_open(item, index), expand image(path) a PNG or GIF picture progress(options?) a bar from 0 to 100; options: value separator() a thin line row(options?) / column(options?) containers with all of these too; options: expand clear() remove everything inside Every widget gives back a map you can use later: label/button: .set(text) .value() label: .style(name) button: .click() .enable() .disable() input/textarea: .value() .set(text) .clear() .focus() textarea: .append(text) checkbox: .value() .set(bool) select: .value() .set(choice) .options() .set_options(list) table: .add_row(list) .set_rows(rows) .rows() .selected() .selected_index() .select(i) .remove(i) .clear() .count() list_box: .add(item) .set_items(list) .items() .selected() .selected_index() .select(i) .remove(i) .clear() .count() image: .set(path) progress: .set(0..100) .value() Window only: title(text?), menu({"File": {"Open": fn, "-": nil, "Quit": fn}}), status(text), every(ms, fn) and after(ms, fn) (both give a timer with .stop()), key("Ctrl+S", fn) ("Mod" is Cmd on a Mac, Ctrl elsewhere), run() (shows the window and waits until it closes), close(), is_open(). Your functions can take fewer inputs than offered: fn() { } is fine for on_change too. If a function you gave the window hits an error, the window shows it in a friendly message and keeps going.

alert(message, title?)

Show a message in a small box with an OK button.

confirm(question, title?)

returns bool

Ask a yes/no question. true means Yes.

ask(question, default?)

returns text

Ask for a line of text in a small box. Gives nil if the person presses Cancel.

open_file(filters?, title?)

returns text

Let the person pick a file to open. filters: a list like [".txt", ".md"] or a map like {"Logs": "*.log"}. Gives the path, or nil if they cancel.

save_file(name?, filters?)

returns text

Let the person choose where to save a file (name is the suggested file name). Gives the path, or nil if they cancel.

pick_folder(title?)

returns text

Let the person choose a folder. Gives its path, or nil if they cancel.

available()

returns bool

True if this computer can open windows (tkinter is installed and this isn't the browser playground).

copy(text)

Put text on the clipboard, ready to paste into another program.

paste()

returns text

The text on the clipboard ("" if there is none).

Values

NameValueWhat it is
gui.THEMES["dark", "light"]The window themes: "dark" and "light".