XUtils

tkD

GUI toolkit for the D programming language based on Tcl/Tk.


#tkd GUI toolkit for the D programming language


Overview

Tkd is a fully cross-platform GUI toolkit based on Tcl/Tk. Tkd allows you to build GUI applications easily and with the knowledge of a consistent, native look and feel on every platform.

Why Tcl/Tk?

Tkd development was initiated based on the performance and uptake of the Tkinter toolkit distributed as a standard part of the Python programming language. Tkinter allows developers easy access to GUI programming with very little learning. Being the de facto GUI toolkit of Python has introduced more developers to GUI application programming and increased the popularity of the language as a whole. Tkd is an attempt to provide D with the same resource.

Example

There is an example in this package which can be built using dub. Clone this repository and use the following command to build this example to see what’s possible.

dub --config=example

The above example.

Documentation

There is full HTML documentation within the repository inside the docs directory.

GUI elements

Windows

These windows are containers for widgets to provide a user interface to the program. Every application has at least one top level window.

Window Description
Window A window is similar to a frame except that it is created as a top level window. The primary purpose of a window is to serve as a dialog box and/or collections of widgets.

Menus allow a user to select options from a predefined list. Menus can be attached to a window (via a menu bar) or popped up independantly.

Menu Description
MenuBar A menubar is the bar across the top of a window holding the menu items.
Menu The cascading menu that items are selected from. These menus can be nested as items in another.

Geometry methods

These methods are used to place widgets onto a window.

Method Description
Grid Geometry method for placing this widget inside its parent using an imaginary grid. Somewhat more direct and intuitive than pack. Choose grid for tabular layouts, and when there’s no good reason to choose something else.
Pack Geometry method for loosely placing this widget inside its parent using a web browser model. Widgets flow around each other in the available space.
Place Geometry method for placing this widget inside its parent using absolute positioning.

Dialog boxes

These are pre-built dialog boxes to gather various pieces of data from a user.

Dialog box Description
ColorDialog Pops up a dialog box for the user to select a color.
DirectoryDialog Pops up a dialog box for the user to select a directory.
FontDialog Pops up a dialog box for the user to select a font.
MessageDialog Pops up a dialog box with a user defined message and buttons.
OpenFileDialog Pops up a dialog box for the user to open a file.
SaveFileDialog Pops up a dialog box for the user to save a file.

Building

  • Tkd has been developed and tested using the latest DMD compiler.
  • It’s recommended to use the dub build tool to build all Tkd projects.

Dependencies

Source code

Tkd requires other D source libraries to correctly use and link against pre-existing C libraries. The source dependencies are as follows:

Dub handles these automatically and during a build acquires them. While building, the tcltk repository is configured to link against the required Tcl/Tk libraries, hence they need to be installed for the application to function.

Windows

You can copy the DLL’s and the initialization script library directory into the root of the finished application. These files can be conveniently found in the dist folder within the tcktk repository. Your finished application’s directory would then look something like this:

project
├── app.exe
├── tcl86t.dll
├── tk86t.dll
└── library
    └── *.tcl files

You can automate this process when building an application by placing the following in the application’s dub.json build file. Dub version 0.9.22 or greater is required.

...
"copyFiles-windows": [
	"$TCLTK_PACKAGE_DIR/dist/$ARCH/tcl86t.dll",
	"$TCLTK_PACKAGE_DIR/dist/$ARCH/tk86t.dll",
	"$TCLTK_PACKAGE_DIR/dist/library",
],
...

Alternatively, if using dub.sdl:

...
copyFiles \
	"$TCLTK_PACKAGE_DIR/dist/$ARCH/tcl86t.dll" \
	"$TCLTK_PACKAGE_DIR/dist/$ARCH/tk86t.dll" \
	"$TCLTK_PACKAGE_DIR/dist/library" \
	platform="windows"
...

Linux/Mac OSX

On Linux and Mac OSX things are a little easier as both operating systems have Tcl/Tk installed by default. If however they do not have the latest version, the libraries can be updated via their respective package managers. The linked libraries are libtcl and libtk.

Notes

Debugging

The following debug flags can be passed to Tkd to help debug certain issues.

-debug=log

Write a log called debug.log in the current directory detailing all Tcl/Tk interaction logging all commands the Tcl interpreter is executing. (All errors are marked as WARN.)

-debug=showTclErrors

Write all Tcl/Tk errors to stdout. This is useful to immediately be notified of interpreter errors without trawling through the debug log.

Widgets

Canvas

The postscript methods of this widget havn’t been implemented yet due to time. This means no exporting to postscript files or printing is available from this widget. This can be added in the future if there is need.

Text

The extended text editing functionality of this widget has not been implement because there are better, more modern editor widgets available separately. This control is not indended to be used as a fully featured text editor.


Articles

  • coming soon...