#widgets #tk #gui-applications #binding #wish #toolkit

afrish

A Rust binding for the Tk graphics toolkit, made for building the Afrim IME

1 unstable release

0.1.0 Sep 6, 2024

#719 in GUI

MIT license

200KB
4.5K SLoC

afrish

A Rust binding for the Tk graphics toolkit, designed specifically for the development of the Afrim IME.

Overview

afrish opens and communicates with Tk's wish program as a separate process. The library provides:

  • low-level functions to directly communicate with wish, suitable for writing additional extensions
  • high-level API to write GUI applications with minimal knowledge of Tk.

Example

A simple hello-world example:

use afrish::*;

fn main() {
  let root = afrish::start_wish().unwrap();

  let hello = afrish::make_label(&root);
  hello.text("Hello from Rust/Tk");

  hello.grid().layout();

  afrish::mainloop();
}

Credits

This project is a clone of rstk.


lib.rs:

A Rust binding for the Tk graphics toolkit.

afrish opens and communicates with Tk's wish program as a separate process. The library provides:

  • low-level functions to directly communicate with wish, suitable for writing additional extensions
  • high-level API to write GUI applications with minimal knowledge of Tk.

The top-level functions to start/stop the GUI are contained in the [wish] module.

The remaining modules describe a widget or supporting component (such as a font or image). Each widget has a constructor function, usually named "make_WIDGET", and this returns a struct of name "TkWIDGET".

Click on the struct name to get a list of methods supported by the widget; functionality is divided between various traits, such as TkWidget.

Example

A simple hello-world example:

use afrish::*;

fn main() {
  let root = afrish::start_wish().unwrap();

  let hello = afrish::make_label(&root);
  hello.text("Hello from Rust/Tk");

  hello.grid().layout();

  afrish::mainloop();
}

Widget lifetimes

The Tk process operates independently of your rust program. All references to widgets in rust are merely string names used to 'lookup' the widget when calling out to Tk. As such, widgets will remain live and visible even if a variable referring to them goes out of scope in your rust code. If you wish to destroy a widget, use the destroy method available on all widgets.

No runtime deps