Reference 〉 Hook

CpanelAboveShocks(cpanelCpanel, bgstr|None)

Allows low-level access to either the Tkinter or the Jupyter control panel. Allows the insertion of widgets – either a Tkinter frame (or any subclass of it) or an Ipywidget, as appropriate – above the Shocks panel, as shown by the red stripe.

Required Parameters

  • cpanel Cpanel

    The Cpanel object.

  • bg str|None

    The background color to maintain the alternating striping of the control panel in Tkinter, either '#FFFFFF' or '#EEEEEE'. None if using Jupyter.

Expected Return Value tkinter.Frame|Ipywidgets.DOMWidget

A Tkinter Frame widget attached to the Cpanel window if using the Tkinter frontend, or a displayable Ipython widget if using Jupyter.

Notes and Examples

  1. charwick

    Aug 05, 2020 at 21:52

    This example inserts a checkGrid – a subclass of tkinter.Frame – above the shocks panel, in order to (e.g.) toggle strategies during model setup.

    Note that checkGrids can now be rendered at a higher level with Params.add() instead, setting the type parameter to 'checkgrid' and the opts parameter to a dict of name-label pairs.

    strategies = {
    	'alwaysCooperate': True,
    	'alwaysDefect': True,
    	'randomly': True,
    	'TFT': True,
    	'Tullock': False,
    	'Nydegger': False,
    	'Grofman': False
    #Build the strategies toggle
    def CpanelAboveShocks(cpanel, bg):
    	cpanel.model.strategies = checkGrid(parent=gui.parent, text='Strategies', columns=2, bg=bg)
    	for s,v in strategies.items():
    		cpanel.model.strategies.addCheck(s, s, v)
    	return cpanel.model.strategies
    #Values can be accessed later using gui.model.strategies.items()

    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.