Miscellaneous Stuff

The tks Module

tkStuff - A collection of Tk widgets

class tks.DefaultColors

A container for color names.

class tks.DefaultFonts

A container for font information.

class tks.PickleVar(master=None, value=None, name=None)

A Tkinter variable which stores values as pickled objects.

tks.load_colors()

Load color definitions from the .tksrc file

tks.load_fonts()

Load font definitions from the .tksrc file

tks.parse_geometry(geom)

Return a width, height, x, y tuple from a Tk geometry.

tks.rect_at(point, size, size_y=-1)

Returns a rectangle centred at point. If only size is provided then the rectangle will be a square. The dimensions will be size * 2.

tks.rect_center(rect)

Return the centre of a rectangle as an (x, y) tuple.

Color Functions (tks.color_funcs)

Various functions to manipulate RGB hex, RGB, HSV and HLS colors.

tks.color_funcs.clamp(value)

Clamp a float between 0.0 and 1.0

tks.color_funcs.clamped_tuple(value)

Clamps the values in a tuple between 0.0 and 1.0

tks.color_funcs.color_string_to_color(value, allow_short_hex=True)

Convert a color string to a (color format, value) tuple where the color format is one of rgbhex, rgb, hsv or hls

tks.color_funcs.color_string_to_rgb(value)

Return an RGB tuple from a color string.

tks.color_funcs.color_string_to_tuple(value)

Convert a color string to a tuple of floats.

tks.color_funcs.contrast_color(rgb)

Return either white or black whichever provides the most contrast

tks.color_funcs.hex_string_to_rgb(value, allow_short=True)

Convert from a hex color string of the form #abc or #abcdef to an RGB tuple.

Parameters:
  • value (str) – The value to convert
  • allow_short (bool) – If True then the short of form of an hex value is accepted e.g. #fff
tks.color_funcs.luminosity_transform(color, luminosity=0.05)

Transform an RGB color by a luminosity.

If luminosity is a tuple then the 3 elements are used to transform the red, green and blue values individually. If a float then the same value is used to transform all 3 elements.

tks.color_funcs.rgb_intensity(rgb)

Convert an RGB color to its intensity

tks.color_funcs.rgb_shade(rgb, percent=5)

Create a shade of the RGB color

Parameters:
  • rgb (tuple) – The RGB value for which to calculate the tint
  • percent (int) – Determines the percent between the specified color and the shade
tks.color_funcs.rgb_shades(rgb, base_percent, count, linear=True)

Produce a list of shades from the base color

Parameters:
  • rgb (tuple) – The RGB value for which to calculate the shades
  • base_percent (float) – Determines the factor between the returned colors
  • count (int) – The number of shades to return
tks.color_funcs.rgb_tint(rgb, percent=5)

Create a tinted version of the RGB color

Parameters:
  • rgb (tuple) – The RGB value for which to calculate the tint
  • percent (int) – Determines the percent between the specified color and the tint
tks.color_funcs.rgb_tints(rgb, base_percent, count, linear=True)

Produce a list of tints from the base color

Parameters:
  • rgb (tuple) – The RGB value for which to calculate the tints
  • base_percent (float) – Determines the factor between the returned colors
  • count (int) – The number of tints to return
tks.color_funcs.rgb_to_hex_string(value)

Convert from an (R, G, B) tuple to a hex color.

Parameters:value (tuple) – The RGB value to convert

R, G and B should be in the range 0.0 - 1.0

tks.color_funcs.rgb_to_hls_string(value, dp=3)

Convert from an (R, G, B) tuple to an HLS string.

Parameters:
  • value (tuple) – The RGB value to convert
  • dp (int) – Number of decimal places in the string

R, G and B should be in the range 0.0 - 1.0

tks.color_funcs.rgb_to_hsv_string(value, dp=3)

Convert from an (R, G, B) tuple to an HSV string.

Parameters:
  • value (tuple) – The RGB value to convert
  • dp (int) – Number of decimal places in the string

R, G and B should be in the range 0.0 - 1.0

tks.color_funcs.rgb_to_rgb_string(value, dp=3)

Convert from an (R, G, B) tuple to an RGB string.

Parameters:
  • value (tuple) – The RGB value to convert
  • dp (int) – Number of decimal places in the string

R, G and B should be in the range 0.0 - 1.0

Icon Functions (tks.icon)

tks.icon.set_icon_from_data(root, image_data)

Set the icon for a root window from image data.

Parameters:
  • root – Toplevel window for which to set the icon.
  • image_data (bytes) – The image data to use
tks.icon.set_icon_from_file(root, filename)

Set the icon for a root window from a file.

Parameters:
  • root – Toplevel window for which to set the icon.
  • filename (str) – The filename to read the image data from
tks.icon.set_icon_from_resource(root, package, resource)

Set the icon for a root window to a resource

Parameters:
  • root – Toplevel window for which to set the icon.
  • package (str) – The package in which to find the resource
  • resource (str) – The name of the resource