[R] tcltk: Difficulties creating menus

Dirk Eddelbuettel edd at debian.org
Wed Sep 19 23:15:13 CEST 2001

I am struggling with adding menus to a tcltk application. The following
example (from the O'Reilly book on Perl/Tk) works fine:

#!/usr/bin/perl -w
use Tk;
my $mw = MainWindow->new;
$menub = $mw->Menubutton(-text => "Color")->pack();
foreach (qw/red yellow green blue grey/) {
  $menub->radiobutton(-label => $_, -command => \&set_bg,
                      -variable => \$background_color, -value => $_);
sub set_bg {
  print "Background value is now: $background_color\n";
  $mw->configure(-background => $background_color);

I cannot get anything similar to work under R. Adding a tkmenubutton is
easy, but I fail to get it to "connect" to an actual menu composed of 
check or radiobuttons:

tt <- tktoplevel()
tkpack(mb <- tkmenubutton(tt, text="Color"))
## does nothing
## tkradiobutton(mb, variable=color, text="blue", value="blue",
##              command=set.bg)
## Error: Error in .Tcl(.Tcl.args(...)) :
##  		[tcl] bad option "add": must be cget or configure.
## tkadd(mb, tkcheckbutton, label="blue", variable=color)
## Dito
## tkcmd("add", tkcheckbutton, label="blue", variable=color)
tkpack(tkbutton(tt, text="Quit", command=function()tkdestroy(tt)))

Any pointers or examples would be greatly appreciated.

Thanks,  Dirk

Better to have an approximate answer to the right question 
than a precise answer to the wrong question. -- John Tukey
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list