Skip to content

[R-gui] pseudo radiobutton from check boxes

2 messages · Adrian Dusa

#
Dear list members,

I have a question related to tcltk programming. I'd like to create 4 check 
boxes with different options; that's easy, but I want the 4th option to 
deactivate the first three and viceversa: if any of the first three check 
boxes has been activated, this should deactivate the fourth check box.

I've written a draft code below, but I feel I misunderstand the usage of 
"command". In my mind, this is only activated when the user presses the 
button with the mouse. Instead, it seems like the command is activated each 
time when the button chages its state. Is there another option I could use 
for this purpose?

Thank you in advance,
Adrian

require(tcltk)
top <- tktoplevel()

cbOptions <- c("option1", "option2", "option3", "option4")
cbLabels <- c("Option A:", "Option B:", "Option C:", "Option D:")
initialValues <- c(0, 0, 0, 0)
cbVariable <- tclVar("0")

option13Command <- function() {
    tkconfigure(option4CB, variable=cbVariable)
    }

option4Command <- function() {
    tkconfigure(option1CB, variable=cbVariable)
    tkconfigure(option2CB, variable=cbVariable)
    tkconfigure(option3CB, variable=cbVariable)
    }

option1CB <- tkcheckbutton(top)
option1Variable <- tclVar(initialValues[1])
tkconfigure(option1CB, variable=option1Variable, command=option13Command)
tkgrid(tklabel(top, text=cbLabels[1]), option1CB, sticky="e")

option2CB <- tkcheckbutton(top)
option2Variable <- tclVar(initialValues[2])
tkconfigure(option2CB, variable=option2Variable, command=option13Command)
tkgrid(tklabel(top, text=cbLabels[2]), option2CB, sticky="e")

option3CB <- tkcheckbutton(top)
option3Variable <- tclVar(initialValues[3])
tkconfigure(option3CB, variable=option3Variable, command=option13Command)
tkgrid(tklabel(top, text=cbLabels[3]), option3CB, sticky="e")

option4CB <- tkcheckbutton(top)
option4Variable <- tclVar(initialValues[4])
tkconfigure(option4CB, variable=option4Variable, command=option4Command)
tkgrid(tklabel(top, text=cbLabels[4]), option4CB, sticky="e")
#
As usual, the solution is found immediatly after posting...
The option I was looking for is "deselect", as in:
tkdeselect(option4CB)

Sorry to have waisted your time,
Adrian
On Sunday 28 May 2006 16:45, Adrian DUSA wrote: