navigate.view.custom_widgets.validation.ValidatedSpinbox
- class navigate.view.custom_widgets.validation.ValidatedSpinbox(*args, min_var=None, max_var=None, focus_update_var=None, required=True, value_type=<class 'float'>, **kwargs)
Bases:
ValidatedMixin,SpinboxA spinbox that validates input and can be linked to other widgets.
Deletion always allowed, digits always allowed, if from < 0 ‘-’ is allowed as first char, if increment is decimal ‘.’ allowed, if proposed value is greater than to ignore key if proposed value requires more precision than increment, ignore key On focus out, make sure number is a valid number string and greater than from value If given a min_var, max_var, or focus_update_var, then the spinbox range will update dynamically when those valuse are changed (can be used to link to other widgets)
- __init__(*args, min_var=None, max_var=None, focus_update_var=None, required=True, value_type=<class 'float'>, **kwargs)
Initialize the spinbox
- Parameters:
master (tk.Widget) – The parent widget
from (int or float) – The minimum value of the spinbox
to (int or float) – The maximum value of the spinbox
increment (int or float) – The increment of the spinbox
min_var (tk.Variable) – A variable that will be used to update the minimum value of the spinbox
max_var (tk.Variable) – A variable that will be used to update the maximum value of the spinbox
focus_update_var (tk.Variable) – A variable that will be used to update the value of the spinbox when it loses focus
no_negative (bool) – If True, the spinbox will not allow negative values
no_decimal (bool) – If True, the spinbox will not allow decimal values
required (bool) – If True, the spinbox will require a value
value_type (type) – Numeric type accepted by the spinbox:
intorfloat.precision (int) – The number of decimal places allowed in the spinbox
Methods
__init__(*args[, min_var, max_var, ...])Initialize the spinbox
add_history(event)Add the current value to the history of the widget.
config([cnf])Configure the spinbox and synchronize validation precision.
configure([cnf])Configure the spinbox and synchronize validation precision.
redo(event)Redo the last change that was undone.
set_precision(prec)Set the precision of the spinbox in decimal places.
Trigger the focusout validation of the widget
undo(event)Undo the last change to the widget.
Attributes
- add_history(event)
Add the current value to the history of the widget.
- Parameters:
event (tk.Event) – The event that triggered the history addition
- config(cnf=None, **kwargs)
Configure the spinbox and synchronize validation precision.
The Tk
incrementoption controls the arrow-button step, while this widget’sprecisioncontrols which values pass validation. Keep them in sync whenever the increment changes; callers can still useset_precision()afterwards for an intentional override.
- configure(cnf=None, **kwargs)
Configure the spinbox and synchronize validation precision.
The Tk
incrementoption controls the arrow-button step, while this widget’sprecisioncontrols which values pass validation. Keep them in sync whenever the increment changes; callers can still useset_precision()afterwards for an intentional override.
- redo(event)
Redo the last change that was undone.
- Parameters:
event (tk.Event) – The event that triggered the redo
- set_precision(prec)
Set the precision of the spinbox in decimal places.
Given a precision it will update the spinboxes ability to handle more or less precision for validation. This is separate from the increment value.
- Parameters:
prec (int) – The number of decimal places allowed in the spinbox
Examples
>>> spinbox.set_precision(2)
- trigger_focusout_validation()
Trigger the focusout validation of the widget
- undo(event)
Undo the last change to the widget.
- Parameters:
event (tk.Event) – The event that triggered the undo
- error
The variable to store the error message in
- Type:
tk.StringVar
- focus_update_var
The variable to update when the spinbox loses focus
- Type:
tk.StringVar
- max_var
The maximum value of the spinbox
- Type:
str
- min_var
The minimum value of the spinbox
- Type:
str
- precision
The precision of the spinbox
- Type:
int
- redo_history
The redo history of the widget
- Type:
list
- required
Whether the spinbox requires a value
- Type:
bool
- resolution
The resolution of the spinbox
- Type:
Decimal
- undo_history
The undo history of the widget
- Type:
list
- value_type
Numeric type accepted by the spinbox
- Type:
type
- variable
The variable to store the value of the spinbox in
- Type:
tk.StringVar