Tk Example:Radio buttons are linked using a common variable, which will have the value of the selected button.
package require Tk
set ::onetwothree "3"
pack [radiobutton .one -value "WNBC" -text "New York" -variable onetwothree -command { puts "Play $::onetwothree" }]
pack [radiobutton .two -value "KDKA" -text "Pittsburgh" -variable onetwothree -command { puts "Play $::onetwothree" }]
pack [radiobutton .three -value "WGN" -text "Chicago" -variable onetwothree -command { puts "Play $::onetwothree" }]The results will be that, on stdout, the number of the radiobutton pressed is output.By setting the onetwothree global variable to 3, the 3rd radio button is selected at the beginning of the code.The global variable used with radiobuttons probably should exist, even if just set to an empty string, to ensure the initial state of the buttons is set as expected.LV Would someone mind adding a simple example, with explanation, of the use of radiobutton's new tri-value state? Just curious about the conditions that might lead to using it. http://tip.tcl.tk/110 doesn't really provide background to recognize situations where it comes in handy.
LV In http://tip.tcl.tk/109 , the TIP talks about the appearance of radiobuttons on Unix. The description of the new state, however, is confusing to me. It says:The radiobutton shall (when the indicator is turned on) display an dot mark or other distinguishing icon/symbol that clearly indicates a selected or On state. The unselected or Off state shall be displayed with an empty diamond. The state values will not be indicated by changing relief or background color.So, if I were to take this statement literally, I would expect that by default on unix the radiobutton would change from an empty diamond to a dot mark or other distinguising icon/symbol.What I see, in Tk 8.5, is that by default on unix the radiobutton is not an empty diamond but a dim dot mark and when the state changes, it becomes a bright dot mark. Is there some sort of option or flag to actually get the diamond indicator with the default Tk radiobutton? I notice that on unix, the default ttk::radiobutton is in fact a diamond, both for unselected and selected state.
LV I see in the radiobutton man page that there is an option to set the background color to use when the button is selected. How would you set the background color of the selection image when it is not selected?
See the vertical command, which allows to place the text below the checkfield, on the checkbutton page.
See also
- Lightbutton a pure Tcl package mimicking the radio and the check buttons, with bright and pretty colors.
