Fanning Software Consulting

Creating Checkbox or Radio Buttons

QUESTION: How do I create a checkbox or radio button using widgets? All I seem to be able to produce are push-buttons. And how do I set the initial buttons that I want to have checked?

ANSWER: Contrary to what you might expect, these types of buttons are not created by setting keywords in the Widget_Button creation routine Rather, these buttons are created depending upon the type of base widget that is used as the button's parent widget.

Base widgets created with the NonExclusive keyword set produce checkbox buttons. Base widgets created with the Exclusive keyword set produce radio buttons.

For example, here is the code that produced the buttons in the figure below. Note that the buttons are defined identically in all three examples.

   PRO buttontypes

   tlb = Widget_Base(Title='Push-Buttons', Column=1, Scr_XSize=200)
   button1 = Widget_Button(tlb, Value='Coyote')
   button2 = Widget_Button(tlb, Value='Cow')
   button3 = Widget_Button(tlb, Value='Dog')
   button4 = Widget_Button(tlb, Value='Pig')
   button5 = Widget_Button(tlb, Value='Sheep')

   Widget_Control, tlb, /Realize

   tlb = Widget_Base(Title='Checkbox Buttons', Column=1, Scr_XSize=200, /NonExclusive)
   button1 = Widget_Button(tlb, Value='Coyote')
   button2 = Widget_Button(tlb, Value='Cow')
   button3 = Widget_Button(tlb, Value='Dog')
   button4 = Widget_Button(tlb, Value='Pig')
   button5 = Widget_Button(tlb, Value='Sheep')
   Widget_Control, button1, Set_Button=1
   Widget_Control, button4, Set_Button=1

   Widget_Control, tlb, /Realize

   tlb = Widget_Base(Title=' Radio Buttons', Column=1, Scr_XSize=200, /Exclusive)
   button1 = Widget_Button(tlb, Value='Coyote')
   button2 = Widget_Button(tlb, Value='Cow')
   button3 = Widget_Button(tlb, Value='Dog')
   button4 = Widget_Button(tlb, Value='Pig')
   button5 = Widget_Button(tlb, Value='Sheep')
   Widget_Control, button1, Set_Button=1

   Widget_Control, tlb, /Realize

   END

Setting Initial Buttons On or Off

Checkbox or radio buttons are unchecked or unselected initially. To check them or turn them on, you use the Set_Button keyword to Widget_Control along with the button's widget identifier. See the example above.

Button widgets have different appearances, depending upon base widget attributes.

Google
 
Web Coyote's Guide to IDL Programming