R TclTk coding examples

If you want to use the tcltk package in R (contributed by Peter Dalgaard), you will find here useful hints. This collection of R tcltk tips & tricks was initially compiled by James Wettenhall. It is now maintained by Philippe Grosjean.

Note that I am progressively refreshing these pages. You will see a difference in the presentation for those pages that are updated and tested with latest R version 2.1.1. I intend also to add more material, like the presentation of tcltk2 package than you can download from the SciViews-R web site

Installing Tcl/Tk for R

Make sure you check the "Support Files for Package tcltk" when you install R for Windows. If you are having trouble installing R TclTk in Windows, click here and also read Brian Ripley's R for Windows FAQ in the 'Help' pull-down menu of Rgui.

For other platforms, you have to make sure Tcl/Tk 8.4 is installed.

Basic techniques

Simple toplevel window with an OK button
Message boxes
File open/save dialogs
Pull-down menus and popup menus
A modal dialog box
Simple non-modal dialog with OK and Cancel buttons and a title

Basic widgets

Making a button to trigger a function call
Adding and changing text labels
Checkboxes
Radio buttons
Edit boxes
List boxes

Additional widgets

Text windows (editable or non-editable)
Scrollbars
Drop-down combo boxes
Frames
Sliders
The color-selection widget
Displaying images in tk windows
Using the tk table widget
Using the tree (drill-down) widget
The date entry and calendar widgets
The tabbed notebook widget
The scrollable frame

Advanced tcltk coding

Specifying the layout
Specifying which window is active (focused)
Fonts
Binding events (e.g. a key-press) to functions and generating events
The wait cursor and other cursors
Exception handling
Evaluating R code from a text window (a scripting widget)
Plotting graphs with tkrplot
Interactive graphics with tkrplot

Useful links

Other sources of R tcltk help/examples


Created: James Wettenhall.
Last update: 30 Augustus 2005, by Philippe Grosjean.