GRIDPLUS2 - Using Groups
Home Reference Manpage Examples Download License Contact

GRIDPLUS Groups

The GRIDPLUS "Groups" facility provides a method to set the state (normal/disabled) for a named Group of widgets -or- menu options, with a single command.

The button, checkbutton, dropdown, dateselector, entry, radiobutton, spinbox, tablelist and text GRIDPLUS command modes have a -group option to assign all widgets created using the command mode with a particular Group.

The button, checkbutton, dropdown, dateselector, entry, radiobutton, spinbox and menu command modes also support the % widget option which allows individual widgets within a Grid -or- menu options, to be assigned to the particular Group.

Other (Non-GRIDPLUS) Tcl/Tk widgets, which support a -state option, can also be assigned to a Group using the GRIDPLUS add command mode.

Example

This section contains an example which illustrates the main GRIDPLUS Groups facility features.

The following example assumes that the reader is familiar with the contents of the Grid/Layout page. Information given on that page will not be duplicated here.

Note: The example assumes that the GRIDPLUS package has already been "required" and the commands imported.


Groups Example

Window:

Source Code:

gridplus menu . {
   Menu {
      {Option1}
      {Option2 .doit2 %mygroup1}
      {Option3 %mygroup2}
   }
}

spinbox .myspin -from 0 -to 10 -increment 1 -width 4 -textvariable (.myspin)

gridplus add .myspin -group mygroup2

gridplus entry .myentry -width 25 -title "Entry Fields" {
   {"Field One"   .field1}
   {"Field Two"   .field2 %mygroup1}
   {"Field Three" .field3 %mygroup2}
   {"Spin Box"    @myspin}
}

gridplus radiobutton .myradiobutton -group mygroup1 -title "Radiobuttons" {
   {.rbutton1 "Option One"   +opt1}
   {.rbutton2 "Option Two"   -opt2}
   {.rbutton3 "Option Three" -opt3}
}

gridplus button .mybutton {
   {"Button 1" .button1} {"Button 2" .button2 %mygroup1} {"Button 3" .button3 %mygroup2}
}

gridplus layout .main -wtitle "Groups Example" {
   .myentry     .myradiobutton:ns
   .mybutton:ew -
}

pack .main

Comments:

gridplus menu . {
   Menu {
      {Option1}
      {Option2 %mygroup1}
      {Option3 %mygroup2}
   }
}

Creates a menubar with one menu, which has three options. "Option2 is assigned to group "mygroup1" and "Option3 is assigned to group "mygroup2"
spinbox .myspin -from 0 -to 10 -increment 1 -width 4 -textvariable (.myspin)

Creates a spinbox called ".myspin". The value of the spinbox is associated with the "null" array item "(.myspin)", this allows the value of the spinbox to be set using gpset.
gridplus add .myspin -group mygroup2

Assigns the ".myspin" spinbox to group "mygroup2".
gridplus entry .myentry -width 25 -title "Entry Fields" {
   {"Field One"   .field1}
   {"Field Two"   .field2 %mygroup1}
   {"Field Three" .field3 %mygroup2}
   {"Spin Box"    @myspin}
}

Creates a GRIDPLUS Entry Grid with three entry fields. The ".myspin" spinbox is embedded in the Grid using the "@myspin" option. "Field Two is assigned to group "mygroup1" and "Field Three is assigned to group "mygroup2"
gridplus radiobutton .myradiobutton -group mygroup1 -title "Radiobuttons" {
   {.rbutton1 "Option One"   +opt1}
   {.rbutton2 "Option Two"   -opt2}
   {.rbutton3 "Option Three" -opt3}
}

Creates a GRIDPLUS Radiobutton Grid with three radiobuttons. The -group option assigns all three radiobuttons to group "mygroup1".
gridplus button .mybutton {
   {"Button 1" .button1} {"Button 2" .button2 %mygroup1} {"Button 3" .button3 %mygroup2}
}

Creates a GRIDPLUS Button Grid with three buttons. "Button 2 is assigned to group "mygroup1" and "Button 3 is assigned to group "mygroup2"
gridplus layout .main -wtitle "Groups Example" {
   .myentry     .myradiobutton:ns
   .mybutton:ew -
}

pack .main

Creates a GRIDPLUS layout called ".main" to arrange the widgets in the window, and uses "pack" to display the layout.

Usage:

Command: gridplus set -group mygroup1 -state disabled

Result:-

Command: gridplus set -group mygroup2 -state disabled

Result:-

Command: gridplus set -group mygroup1 -state disabled
...and...
Command: gridplus set -group mygroup2 -state disabled

Result:-

Note: To set a group to the enabled state the "-state normal" option may be used.

For Example:

gridplus set -group mygroup2 -state normal


Copyright © 2013 Adrian Davis.