Skip to content

Utility

The utility module provides a set of utility functions that are used throughout the library for more readable code.

To import all utility functions:

import tailwindall.util as util

Usage

Constants

NameDescriptionTypeValue
stringA string typestrstr
NULLNULL TypeNoneNone
nullAlias for NULLNoneNone

Types

Types is a class that provides multiple classmethods for comparing types.

Are list items the same

To check if the items in two list are the same type:

import tailwindall.util as util
util.Types.are_list_items_same([1, 2, 3], [4, 5, 6]) # [False, False, False]
util.Types.are_list_items_same([1, 2, 3], [1, 2, 4]) # [True, True, False]
util.Types.are_list_items_same([1, 2, 3], [4, 5, 6, 7]) # ValueError: Lists are not the same length: This -> 3 & Other -> 4
Arguments
NameDescriptionTypeDefaultSee Also
thisThe first list to comparelistNo Default
otherThe second list to comparelistNo Default
Return Types
TypeDescriptionExample Values
listA list of booleans that represent if the items in the list are the same type[True, True, False]
ValueErrorIf the lists are not the same lengthValueError: Lists are not the same length: This -> 3 & Other -> 4

Are classes same

To check if two classes have the same __dict__:

import tailwindall.util as util
class A:
def __init__(self):
self.a = 1
self.b = 2
class B:
def __init__(self):
self.a = 1
self.b = 2
class C:
def __init__(self):
self.a = 1
self.b = 2
self.c = 3
util.Types.is_class_same(A(), B()) # {'a': True, 'b': True}
util.Types.is_class_same(A(), C()) # {'a': True, 'b': True, 'c': None}
Arguments
NameDescriptionTypeDefaultSee Also
thisThe first class to compareclassNo Default
otherThe second class to compareclassNo Default
Return Types
TypeDescriptionExample Values
dictA dictionary of booleans that represent if the items in the class are equal, if item in return dict is None, it means the classes did not both have the variable{'a': True, 'b': True, 'c': None}

Is same type

To check if two variables are the same type:

import tailwindall.util as util
util.Types.is_type(1, 2) # True
util.Types.is_type(1, '1') # False
Arguments
NameDescriptionTypeDefaultSee Also
thisThe first variable to checkanyNo Default
otherThe second variable to checkanyNo Default
Return Types
TypeDescriptionExample Values
boolA boolean that represents if the two variables are the same type or notTrue

Is Instance

Returns if the variable is an instance of the class:

import tailwindall.util as util
util.Types.is_instance(1, int) # True
util.Types.is_instance(1, str) # False
Arguments
NameDescriptionTypeDefaultSee Also
thisThe variable to checkanyNo Default
otherThe class to check againstclassNo Default
Return Types
TypeDescriptionExample Values
boolA boolean that represents if the variable is an instance of the class or notTrue

Widget Type

Returns the type of the widget:

import tailwindall.util as util
import tailwindall.widgets as widgets
util.Types.widget_type(widgets.Button(
# arguments here
)._ctk) # 'Button'
Arguments
NameDescriptionTypeDefaultSee Also
thisThe widget to get the type ofAny widget from widgets ._ctkNo Default
Return Types
TypeDescriptionExample Values
strA string that represents the type of the widget or 'unknown' if not known'Button'

Read File

Reads a file and returns the contents:

import tailwindall.util as util
util.read_file('file.txt') # 'contents of file.txt'
util.read_file('non-existent-file.txt') # FileNotFoundError: File Not Found: non-existent-file.txt
Arguments
NameDescriptionTypeDefaultSee Also
fileThe file to readstrNo Default
optionsThe options to read the file withdict{}File Open Options
File Import Options
NameDescriptionTypeDefaultSee Also
stripIf the file should be stripped of whitespaceboolFalse
linesIf the file should be read line by lineboolFalse
Return Types
TypeDescriptionExample Values
strA string that represents the contents of the file or '' if file is empty'Button'
FileNotFoundErrorIf the file does not existFileNotFoundError: File Not Found: non-existent-file.txt

Pass

A function that does nothing:

import tailwindall.util as util
util._pass() # None
Arguments
NameDescriptionTypeDefaultSee Also
None
Return Types
TypeDescriptionExample Values
None

Anchors

A class that provides multiple classmethods for anchoring widgets.

To get the anchor value to be passed into the window.Window.add_widget method:

import tailwindall.util as util
util.CenterAnchor.get_anchor() # Get Center Anchor

Center Anchor

import tailwindall.util as util
util.CenterAnchor.get_anchor() # Get Center Anchor

North Anchor

import tailwindall.util as util
util.NorthAnchor.get_anchor() # Get North Anchor

South Anchor

import tailwindall.util as util
util.SouthAnchor.get_anchor() # Get South Anchor

East Anchor

import tailwindall.util as util
util.EastAnchor.get_anchor() # Get East Anchor

West Anchor

import tailwindall.util as util
util.WestAnchor.get_anchor() # Get West Anchor

North East Anchor

import tailwindall.util as util
util.NorthEastAnchor.get_anchor() # Get North East Anchor

North West Anchor

import tailwindall.util as util
util.NorthWestAnchor.get_anchor() # Get North West Anchor

South East Anchor

import tailwindall.util as util
util.SouthEastAnchor.get_anchor() # Get South East Anchor

South West Anchor

import tailwindall.util as util
util.SouthWestAnchor.get_anchor() # Get South West Anchor

Image Scale

This is a class containing the x and y scaling factors for images.

To create an instance of the class:

from tailwindall.util import ImageScale
ImageScale(1, 1) # ImageScale(x, y)

Arguments

NameDescriptionTypeDefaultSee Also
xThe x scale factorintNo Default
yThe y scale factorintNo Default

Execute list

Executes a list of functions and finishes by executing the final function if provided.

import tailwindall.util as util
util.exec_list([lambda: print('Hello'), lambda: print('World')], final=lambda: print('!')) # Hello\nWorld\n!
Arguments
NameDescriptionTypeDefaultSee Also
functionsThe list of functions to executelist[function]No Default
finalThe final function to executefunctionNone

Style

An extension of the styles.Styles class

A class that allows for manual entry of styles.

To create an instance of the class:

from tailwindall.util import Style
style = Style({}, {}, {}) # Style(classes, tags, ids)

Arguments

NameDescriptionTypeDefaultSee Also
classesdict[str, str]No Default
tagsdict[str, str]No Default
idsdict[str, str]No Default

Class Methods

Empty

Returns an empty style:

from tailwindall.util import Style
Style.empty() # Style({}, {}, {})

Resizable

A class that holds weather something is resizable or not (in the x or y axis).

To create an instance of the class:

from tailwindall.util import Resizable
Resizable(True, True) # Resizable(x, y)

Arguments

In the x or y arguments, None also means that the widget is not resizable in that axis

NameDescriptionTypeDefaultSee Also
xWhether the widget is resizable in the x axisboolNone
yWhether the widget is resizable in the y axisboolNone

Class Methods

Empty

Returns an empty resizable:

from tailwindall.util import Resizable
Resizable.empty() # Resizable(None, None)

Window Properties

A class that holds the properties of a window.

To create an instance of the class:

from tailwindall.util import WindowProperties, resolution
WindowProperties(dynamic_scaling=True, dev_resolution=resolution(1920, 1080))

Arguments

NameDescriptionTypeDefaultSee Also
dynamic_scalingWhether the window should scale dynamically based on the resolutionboolNone
dev_resolutionThe resolution used when developing (used to scale the widgets to) when dynamic_scaling is Trueutil.resolutionNoneResolution
sizeThe size of the windowutil.resolutionNoneResolution
resizableWhether the window is resizableutil.ResizableNoneResizable
appearance_modeThe appearance mode of the windowstrNone
default_color_themeThe default color theme of the windowstrNone
css_fileThe css file to use for the windowstrNone

Class Methods

Empty

Returns an empty window properties:

from tailwindall.util import WindowProperties
WindowProperties.empty() # WindowProperties(None, None, None, None, None, None, None)

Place Data

A class that holds the data for placing widgets.

To create an instance of the class:

from tailwindall.util import PlaceData, CenterAnchor
PlaceData(0, 0, CenterAnchor.get_anchor())

Arguments

NameDescriptionTypeDefaultSee Also
xThe x position of the placementfloatNo Default
yThe y position of the placementfloatNo Default
anchorThe center point of the placement (0.5, 0.5)Anchor from utilNo Default

Is Main Thread

Returns if the current thread is the main thread:

otherfile.py

import tailwindall.util as util
print(util.is_main_thread(__name__)) # False, because it is imported

main.py

import tailwindall.util as util
import otherfile
print(util.is_main_thread(__name__)) # True, because it is directly ran

Run Tests

Runs the tests for any library or file:

file

import tailwindall.util as util
tests = [lambda: print('Hello'), lambda: print('World')]
util.run_tests(tests)

output

Terminal window
Testing...
Tests: 0. Passed: 0. Running Test 1...
Hello
Result: None
Tests: 1. Passed: 1. Running Test 2...
World
Result: None
===============================
Tests: 2. Passed: 2.
===============================
All tests passed!

Resolution

A class that holds the resolution of a window.

To create an instance of the class:

from tailwindall.util import resolution
resolution(1920, 1080) # resolution(width, height)

Arguments

NameDescriptionTypeDefaultSee Also
widthThe widthintNo Default
heightThe heightintNo Default