Widgets¶
Standard UI widgets for building interfaces.
Checkbox¶
checkbox.py — Checkbox widget for myTk UI framework.
This module defines a Checkbox class that wraps a ttk.Checkbutton widget, providing data binding via BooleanVar, user-defined callbacks, and convenient label configuration.
- Classes:
Checkbox: A bindable checkbox with support for value access and change notifications.
Example
from mytk.checkbox import Checkbox
- def on_toggle(checkbox):
print(“Checkbox state:”, checkbox.value)
box = Checkbox(label=”Accept terms”, user_callback=on_toggle)
- class mytk.checkbox.Checkbox(*args, label='', user_callback=None, **kwargs)[source]¶
Bases:
BaseA wrapper around ttk.Checkbutton that supports data binding and a user callback.
Provides: - BooleanVar synchronization - User-defined callback on state change - Label configuration via constructor
- property value¶
Gets the current checked state of the checkbox.
- Returns:
True if checked, False if unchecked.
- Return type:
- create_widget(master, **kwargs)[source]¶
Creates the ttk.Checkbutton widget and binds its variable.
- Parameters:
master (tk.Widget) – The parent widget into which this widget is placed.
**kwargs – Additional keyword arguments.
- value_changed()[source]¶
Called when the checkbox value changes. Invokes the user callback if defined.
- Raises:
RuntimeError – If the user callback raises an exception.
Labels¶
- class mytk.labels.Label(text=None, wrapping=False, **kwargs)[source]¶
Bases:
BaseA text label widget wrapping ttk.Label with optional word wrapping.
Entries¶
- class mytk.entries.Entry(*args, value='', character_width=None, **kwargs)[source]¶
Bases:
BaseA single-line text entry widget wrapping ttk.Entry.
- property character_width¶
Get or set the entry width in characters.
- property width¶
Get the entry width in pixels.
- Raises:
NotImplementedError – If the widget has not been placed yet.
- class mytk.entries.FormattedEntry(*args, value=0, character_width=None, format_string=None, reverse_regex=None, **kwargs)[source]¶
Bases:
BaseA text entry that formats its numeric value using a format string and regex.
- property value¶
Get or set the numeric value, applying the format string on change.
- property character_width¶
Get or set the entry width in characters.
- class mytk.entries.CellEntry(*args, tableview, item_id, column_name, user_event_callback=None, **kwargs)[source]¶
Bases:
BaseAn inline entry widget for editing a single cell in a TableView.
- class mytk.entries.IntEntry(*args, value=0, width=None, minimum=0, maximum=100, increment=1, **kwargs)[source]¶
Bases:
BaseAn integer spinbox entry with configurable minimum, maximum, and increment.
- property value¶
Get or set the integer value, clamped to the configured range.
- property minimum¶
Get or set the minimum allowed value.
- property maximum¶
Get or set the maximum allowed value.
- property increment¶
Get or set the step increment for the spinbox.
Slider¶
- class mytk.controls.Slider(value=0, minimum=0, maximum=100, increment=1, width=200, height=20, orient='horizontal', delegate=None)[source]¶
Bases:
BaseA horizontal or vertical slider control for selecting numeric values.
- property value¶
The current numeric value of the slider.
- property minimum¶
The minimum allowed value of the slider.
- property maximum¶
The maximum allowed value of the slider.