This module defines a Control class and several derivatives. A Control is a special-purpose GUI widget for setting a value such as a number or filename.
A specialized GUI widget that controls a command-line option.
Control subclasses may have any number of sub-widgets such as labels, buttons or entry boxes; one of the sub-widgets should be linked to self.variable like so:
textbox = tk.Entry(self, textvariable=self.variable)
See the Control subclasses below for examples of how self.variable, get() and set() are used.
Create a Control for an option.
Arguments:
- vartype
- Python type of stored variable (str, bool, int, float, list, dict)
- label
- Label shown in the GUI for the Control
- option
- Command-line option associated with this Control, or empty to create a positional argument
- default
- Default value for the Control
- help
- Help text to show in a tooltip
- toggles
- Control widget may be toggled on/off
- labelside
- Position of label (‘left’ or ‘top’). It’s up to the derived Control class to use this appropriately.
- kwargs
- Keyword arguments of the form key1=arg1, key2=arg2
Add a callback to this Control, which will be called anytime the Control’s value is modified. The callback will be called with a single argument: this Control instance. Callbacks will only be added once.
Return the Control instance for a given option string, or None if no Control has that option string.
Draw the control widgets in the given master.
Override this method in derived classes, and call the base class method:
Control.draw(self, master)
Set the focus to this Control. Override in subclasses if needed.
Return the value of the Control’s variable.
Return a list of arguments for passing this command-line option. draw must be called before this function.
Post-draw initialization.
Reset the Control’s value to the default.
Set the Control’s variable to the given value.
Set control options from the given list of command-line arguments, and remove any successfully parsed options and arguments from args.
Set the Control to reference the given Tkinter variable.
Enable or disable the Control when self.check is toggled.
Multiple-choice selector, with radiobutton or dropdown style.
Initialize Choice widget with the given label and list of choices.
Draw control widgets in the given master.
A color chooser that may have ‘#RRGGBB’ or ‘ColorName’ values.
Create a widget that opens a color-chooser dialog.
Draw control widgets in the given master.
Return an 8-bit ‘#RRGGBB’ hex string for the given color. If a given color name is unknown, return ‘#FFFFFF’ (white).
Change the button background color to the given RGB hex value.
Event handler for the color picker button; choose and set a color.
Set the current color to an RGB hex value or color name.
Event handler to update the color preview.
Filename entry box with browse button.
Create a Filename with label, text entry, and browse button.
Event handler when browse button is pressed
Draw control widgets in the given master.
Yes/no checkbox, for flag-type options.
Create a Flag widget with the given label and default value.
Draw the Flag in the given master widget.
Enable/disable related Controls based on Flag state.
Like a normal Flag, but has an optional argument following it.
Create a FlagOpt widget; like a Flag, but has an optional argument which may be set using an associated Control.
- label
- Text label for the flag
- option
- Command-line flag passed
- default
- Default value (True or False)
- help
- Help text to show in a tooltip
- control
- Another Control, for setting the argument value (required)
Draw the Flag and associated Control in the given master.
Enable or disable the arg Control when the flag changes.
If the flag is enabled, return the flag and associated option.
Font name chooser.
Create a widget that opens a font chooser dialog.
Open a font chooser to select a font.
Draw the Font selector in the given master widget.
A list of values, editable with a given Control.
Examples:
List('Filenames', '-files', control=Filename())
List('Colors', '-colors', control=Color())
List('Texts', '-texts', control=Text())
List('Choices', '-choices', control=Choice())
Create a control for a list-type option.
Event handler for the “Add” button.
Draw the List and associated Control in the given master.
Event handler when the Control’s variable is modified.
Enable the Control if there are items in the list, otherwise disable it.
Event handler for the “Remove” button.
Select an item in the list and enable editing.
Set all list values.
Set the List to use the given ListVar as its variable.
A List with one value for each value in a parent list.
This is like a regular List, except that it has a parent:child relationship of 1:1 (each parent item has a one child item).
Behavior:
- Each item in parent list maps to one item in the child list
- Parent copy and child list scroll in unison
- If item in child list is selected, parent item is selected also
- Drag/drop is allowed in parent list only
Assumptions:
- If item in parent is selected, child item/list is selected also
- It item is added to parent, new child item/list is added also
- If item in parent is deleted, child item/list is deleted also
- Child option string is only passed once
Create a list having a 1:1 mapping to another List.
Add callback functions for add/remove in the parent Control.
Draw the parent copy and related list Control, side by side in the given master.
Return a list of arguments for the contained list(s).
A List with many values for each value in a parent list.
This is like a regular List, except that it has a parent:child relationship of 1:* (each parent item has a list of child items).
Behavior:
- Each item in parent list maps to a list of items in the child list
- Parent copy and child list scroll independently
- If item in child is selected, parent is unaffected
- Drag/drop is allowed in the child Control
Assumptions:
- If item in parent is selected, child item/list is selected also
- It item is added to parent, new child item/list is added also
- If item in parent is deleted, child item/list is deleted also
- Child option string is only passed once
Create a list having a 1:* mapping to another List.
- parent
- Parent List object, or the option string of the parent List control declared elsewhere
- filter
- A function that translates parent values into child values
- side
- Pack the parent to the ‘left’ of child or on ‘top’ of child
Keyword arguments:
- index
- True to pass an additional argument between the child list’s option and arguments with the 1-based index of the child list.
Add callback functions for add/remove in the parent Control.
Draw the parent copy and related list Control, side by side in the given master.
Return a list of arguments for the contained list(s).
Reset the list values to empty.
Append the given items to listvars.
Numeric entry box or slider.
Create a number-setting widget.
- label
- Text label describing the meaning of the number
- option
- Command-line option to set
- default
- Default value
- help
- Help text to show in a tooltip
- min, max
- Range of allowable numbers (inclusive)
- units
- Units of measurement (ex. ‘kbits/sec’), used as a label
- style
- ‘spin’ for a spinbox, ‘scale’ for a slider, ‘popup’ for a slider in a popup window
- step
- For ‘scale’ style, the amount to increment or decrement when the slider is moved
The default/min/max may be integers or floats.
Draw the Number entry in the given master widget.
Enable or disable all sub-widgets.
Text string interpreted as a space-separated list of strings
Draw SpacedText control in the given master widget.
Get current text, split into a list of strings.
Set the text equal to the given list, joined with spaces and double-quoted. Double-quotes in list values are backslash-escaped.
Text string entry box.
Create a text-entry control.
Draw the Text control in the given master widget.
Highlight the text entry box for editing.
Select the next item in the parent listbox.
Set the parent List control.