Reference 〉 Class

checkGrid(parenttkinter.FrameNone, textstr'', columnsint3, fgstr'#333', bgstr'#FFF', padxint8, padyintNone, fonttuple(str,int)None, startOpenboolTrue)

The checkGrid class is an expandableFrame widget filled with textCheck widgets, along with setter and getter methods to interact with the latter by key.

checkGrid is a subclass of expandableFrame, and thus has all the methods and properties of that class as well. These are not listed here.

checkGrid is subscriptable. The value of the textCheck added with the name 'x' can be retrieved with checkGrid['x'], and toggled by setting checkGrid['x']=True or False.

Note that this is a Tkinter widget and thus will not work in other frontends like Jupyter notebooks. The recommended way to draw a custom checkGrid is with the higher-level Params.add() instead, setting the type parameter to 'checkgrid' and the opts parameter to a dict of name-label pairs.

WARNING: This is an internal class. Its use in user code is not recommended or supported, and its signature can change in future updates without warning. Use one of the suggested functions above instead, if applicable.

Initialization Parameters

  • parent tkinter.Frame, optional

    The Tkinter frame to which the widget should be attached.

    Default value: None

  • text str, optional

    The title of the frame, clickable to expand and collapse.

    Default value: ''

  • columns int, optional

    The number of columns in which to insert textCheck widgets.

    Default value: 3

  • fg str, optional

    A hex value for the text color.

    Default value: '#333'

  • bg str, optional

    A hex value for the background color.

    Default value: '#FFF'

  • padx int, optional

    The container frame's horizontal padding.

    Default value: 8

  • pady int, optional

    The container frame's vertical padding.

    Default value: None

  • font tuple(str,int), optional

    A font name/size pair.

    Default value: None

  • startOpen bool, optional

    If True, the frame is drawn expanded initially. If False, the frame is drawn collapsed initially.

    Default value: True


Click a method name for more detailed documentation.

  • addCheck( var, text, defaultValue, … )

    Adds a textCheck element to the frame.

  • disable( key )

    Disables one or all textCheck(s) attached to the frame.

  • disabled( key, val )

    Enables or disables a textCheck.

  • enable( key )

    Enables one or all textCheck(s) attached to the frame.

  • items( )

    Returns a list of tuples corresponding to key-value pairs of the added textCheck objects, by analogy to dict.items().

  • keys( )

    Returns a list of names of registered checks, by analogy to dict.keys().

  • toggle( )

    Expands a collapsed frame, and collapses an expanded frame.

    Note that the function signature takes one optional argument, a Tkinter event string, in order to be used as a callback for a click event. This argument is not used in the function.

  • values( )

    Returns a list of textCheck items, by analogy to dict.values().

Object Properties

  • padx int

    The container frame's horizontal padding.

  • pady int

    The container frame's vertical padding.

  • text str

    The title of the expandable frame.

  • titleLabel tkinter.Label

    The Tkinter Label element corresponding to the clickable title.

  • open tkinter.IntVar

    Whether the frame is expanded or collapsed. Setting this parameter will also open and close the frame.

    Initial value: bool

  • subframe tkinter.Frame

    The Tkinter Frame element that gets expanded and collapsed. Can be interacted with and have elements placed into it like any Frame element.

    Initial value:

  • buttons dict{str: Btn}

    A dictionary with elements 'right' and 'left' containing two action buttons that can be placed on either side of the frame's title. Used in CheckGrids for the toggle-all button, for example.

    Initial value: dict{'left': Btn(), 'right': Btn()}

  • columns int

    The number of columns in which to insert textCheck widgets.

    Initial value: 3

  • checks dict{str:textCheck}

    The textCheck widgets to be displayed.

    Initial value: {}

Notes and Examples

  1. charwick

    Mar 27, 2020 at 21:34

    Checkgrids can be inserted using GUI hooks where there are lots of values to toggle. This example toggles strategies and puts the checkGrid object in model.strategies for the values to be retrieved later.

    strategies = {
    	'alwaysCooperate': True,
    	'alwaysDefect': True,
    	'randomly': True,
    	'TFT': True,
    	'Tullock': False,
    	'Nydegger': False,
    	'Grofman': False
    #Build the strategies toggle
    def CpanelAboveShocks(gui, bg):
    	gui.model.strategies = checkGrid(parent=gui.parent, text='Strategies', columns=2, bg=bg)
    	for s,v in strategies.items():
    		gui.model.strategies.addCheck(s, s, v)
    	return gui.model.strategies
    #Use the values later in the model to instantiate breeds
    def modelPreSetup(model):
    	for k,v in model.strategies.items():
    		if v.get(): model.addBreed(k, '#000000')

    This results in the following panel:

    checkGrid Example

  2. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.