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§

pub use button::*;
pub use canvas::*;
pub use chart::*;
pub use check_button::*;
pub use combobox::*;
pub use dialog::*;
pub use entry::*;
pub use font::*;
pub use frame::*;
pub use grid::*;
pub use image::*;
pub use label::*;
pub use label_frame::*;
pub use listbox::*;
pub use menu::*;
pub use notebook::*;
pub use pack::*;
pub use paned_window::*;
pub use progressbar::*;
pub use radio_button::*;
pub use scale::*;
pub use scrollbar::*;
pub use separator::*;
pub use spinbox::*;
pub use text::*;
pub use theme::*;
pub use toplevel::*;
pub use treeview::*;
pub use widget::*;
pub use wish::*;

Modules§

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