Smart Widgets

Smart widgets consist of existing widgets with improved API. In most cases, these widgets will simply incorporate the appropriate type of xVar for the widget type. For instance, imaging providing for an OptionMenu without having to use a StringVar. These widgets generally appear the same as their ordinary counterparts that are already present within the library.

SmartOptionMenu

class widgets.SmartOptionMenu(parent, options: list, initial_value: str = None, callback: callable = None)

Classic drop down entry with built-in tracing variable.:

# create the dropdown and grid
som = SmartOptionMenu(root, ['one', 'two', 'three'])
som.grid()

# define a callback function that retrieves
# the currently selected option
def callback():
print(som.get())

# add the callback function to the dropdown
som.add_callback(callback)
Parameters:
  • data – the tk parent frame
  • options – a list containing the drop down options
  • initial_value – the initial value of the dropdown
  • callback – a function

SmartSpinBox

class widgets.SmartSpinBox(parent, entry_type: str = 'float', callback: callable = None, **options)

Easy-to-use spinbox. Takes most options that work with a normal SpinBox. Attempts to call your callback function - if assigned - whenever there is a change to the spinbox.:

# create a callback function
def callback(value):
    print('the new value is: ', value)

# create the smart spinbox and grid
ssb = SmartSpinBox(root, from_=0, to=5, callback=callback)
ssb.grid()
Parameters:
  • parent – the tk parent frame
  • entry_type – ‘str’, ‘int’, ‘float’
  • callback – python callable
  • options – any options that are valid for tkinter.SpinBox

SmartCheckbutton

class widgets.SmartCheckbutton(parent, callback: callable = None, **options)

Easy-to-use check button. Takes most options that work with a normal CheckButton. Attempts to call your callback function - if assigned - whenever there is a change to the check button.:

# create the smart spinbox and grid
scb = SmartCheckbutton(root)
scb.grid()

# define a callback function that retrieves
# the currently selected option
def callback():
    print(scb.get())

# add the callback function to the checkbutton
scb.add_callback(callback)
Parameters:
  • parent – the tk parent frame
  • callback – python callable
  • options – any options that are valid for tkinter.Checkbutton

BinaryLabel

_images/byte-label.png
class widgets.BinaryLabel(parent, value: int = 0, prefix: str = '', bit_width=8, **options)

Displays a value binary. Provides methods for easy manipulation of bit values.:

# create the label and grid
bl = BinaryLabel(root, 255)
bl.grid()

# toggle highest bit
bl.toggle_msb()
Parameters:
  • parent – the tk parent frame
  • value – the initial value, default is 0
  • options – prefix string for identifiers
clear_bit(position: int)

Clears the value at position

Parameters:position – integer between 0 and 7, inclusive
Returns:None
clear_lsb()

Clears the least significant bit :return: None

clear_msb()

Clears the most significant bit :return: None

get()

Return the current value

Returns:the current integer value
get_bit(position: int)

Returns the bit value at position

Parameters:position – integer between 0 and <width>, inclusive
Returns:the value at position as a integer
get_lsb()

Returns the least significant bit as an integer :return: the LSB

get_msb()

Returns the most significant bit as an integer :return: the MSB

set(value: int)

Set the current value

Parameters:value
Returns:None
set_bit(position: int)

Sets the value at position

Parameters:position – integer between 0 and 7, inclusive
Returns:None
set_lsb()

Sets the least significant bit :return: None

set_msb()

Sets the most significant bit :return: None

toggle_bit(position: int)

Toggles the value at position

Parameters:position – integer between 0 and 7, inclusive
Returns:None
toggle_lsb()

Toggles the least significant bit :return:

toggle_msb()

Changes the most significant bit :return: None

ByteLabel

_images/byte-label.png
class widgets.ByteLabel(parent, value: int = 0, prefix: str = '', bit_width=8, **options)

Has been replaced with more general BinaryLabel. Still here for backwards compatibility.