Playing with Tk

From RevaWiki

Jump to: navigation, search

This is for Reva 6.0.3 and Linux.

Contents

What is Tk?

Tk is a small toolkit running on Unix/Windows/Mac. It's often used from within Tcl, but it also has a C interface. Tcl and Tk are developed to be integrated easily in other applications - there it usually acts as glue between parts of the application and can be used to give the user some possibilities to customize the application.

What you need

  • You need the Tcl/Tk libraries installed on your system. For reva-tk-test.f you need Tix (an extension to Tk) installed too. Many Linux systems do have these libraries installed by default or they can be simply installed by the package management of the distribution.

and unpack it to some directory you prefer for tests and playing around.

Starting the thing

Simply type
reva <reva-tk-test.f
on a command line. If everything works, you'll see something like:

Image:Revatk.png

Playing a little more

You can start the Tk-interface also by

reva reva-tk

The system starts up in FORTH, so you can add some definitions. A simple definition of a Tcl-command in FORTH looks like:

tcl: tcl-command ." Hello!" TCL_OK ;

You can test it from FORTH by:

tcl" tcl-command"

A very useful defintion if you want to enter the UI is:

: bye   tcl" destroy ." ;

To enter the UI simply type

main

The prompt then changes from FORTH prompt to Tcl-prompt (%), very similar to that given by the "wish" command. To invoke FORTH from Tcl you can use the following command - eg.:

forth words

Or a little longer

forth {." This is a simple example"}

Have Fun! Helmar 03:49, 22 March 2006 (PST)

Problems on Windows

I currently do have only very restricted possibilities to test under Windows. I've used ActiveState Tcl and as far as I can see the things are working up to some misterious point. I fixed the library loading commands to load tk84.dll and tcl84.dll.

The Tcl-interface is initialized correctly. The
reva reva-tk
works perfectly and you can play around with defining new Tcl commands or invoke FORTH from the Tcl interpreter. At the moment you start
main
there seems to be something missing. It seems on Windows Tk needs some additional initialization - I could imagine this is because on Windows there are no default installation paths for the libraries (but well, I ask why not use registry then...)

But fortunately the things work half - you can play and build an interface using the Tcl-prompt. It also works to invoke FORTH. But the event-loop of Tk seems not to work correct. This should be because of the failed initialization... So if anyone has more experience on Windows, it would be nice to take a look inside. Helmar 02:43, 23 March 2006 (PST)

Personal tools