Crate rstk

source ·
Expand description

A Rust binding for the Tk graphics toolkit.

rstk 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.

For examples and additional documentation, see the project webpage.

Example

A simple hello-world example:

use rstk::*;

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

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

  hello.grid().layout();

  rstk::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.

Re-exports

Modules

  • Button widget - displays text/image. Executes a command when clicked.
  • Canvas widget - displays (interactive) graphics.
  • Plotchart wrapper - draws different kinds of charts on a canvas.
  • Check button widget - displays text/image with an on/off widget. Executes a command when clicked.
  • Combobox widgets - text field with a drop-down list of options.
  • Dialogs - various built-in dialogs.
  • Entry widget - text field for user input or editing.
  • Font - support for defining and customising fonts.
  • Frame widget - a container widget for other widgets.
  • Grid layout - a geometry manager for arranging widgets.
  • Images - method to read in an image from file.
  • Label widgets - displays text/image.
  • Label-frame widget - a container widget for other widgets; like frames but with an optional text label.
  • Listbox widget - displays a list of items from which the user can select one or more.
  • Menu widget - for building menubars and menus.
  • Notebook widget - a container widget which contains multiple panes, but displays one pane at a time.
  • Pack layout - a geometry manager for arranging widgets.
  • Paned-window widget - a container widget which contains multiple panes. Resizable sizers separate each pane.
  • Progressbar widget - displays feedback on progress through a task.
  • Radio button widget - displays text/image with an on/off widget, arranged in a group of mutually exclusive buttons. Executes a command when clicked.
  • Scale widget - displays a slider over a range.
  • Scrollbar widget - displays a scrollbar to control position within a range.
  • Separator widget - displays a separating line in its parent.
  • Spinbox widget - displays a range with up/down buttons.
  • Text widget - displays text.
  • Themes - functions to list and set the overall theme (look and feel) of the Tk program.
  • Toplevel widget - defines top-level and popup windows.
  • Treeview widget - displays hierarchical data with multiple values.
  • Functions and definitions applying to all widgets or specific sub-classes of widgets.
  • Core functions and data structures for interacting with the wish process.