跳转至

tkintertools.toolbox.tools

字数 325 个   代码 51 行   阅读时间 2 分钟   访问量

Some useful utility classes or utility functions

🟢_Trigger

class protected | object

1
2
3
4
def __init__(
    self,
    command: typing.Callable,
) -> None: ...

Single trigger

It can only be triggered once before the reset, and multiple triggers are invalid. When triggered, the callback function is called.

  • command: the function that is called when triggered

🟡get

method public

1
2
3
def get(
    self,
) -> bool: ...
Get the status of the trigger

🟡lock

method public

1
2
3
def lock(
    self,
) -> None: ...
Lock the trigger so that it can’t be updated

🟡reset

method public

1
2
3
def reset(
    self,
) -> None: ...
Reset the status of the trigger

🟡unlock

method public

1
2
3
def unlock(
    self,
) -> None: ...
Unlock this trigger so that it can be updated again

🟡update

method public

1
2
3
4
5
6
def update(
    self,
    value: bool = True,
    *args,
    **kwargs,
) -> None: ...

Update the status of the trigger

value: updated value

🔵embed_window

function public

1
2
3
4
5
6
def embed_window(
    window: Misc,
    parent: tkinter.Misc | None,
    *,
    focus: bool = False,
) -> None: ...

Embed a widget into another widget

  • window: Widget that will be embedded in
  • parent: parent widget, None indicates that the parent widget is the screen
  • focus: whether direct input focus to this window

🔵get_hwnd

function public

1
2
3
def get_hwnd(
    widget: Widget,
) -> int: ...
Get the HWND of tkinter.Widget

🔵get_text_size

function public

1
2
3
4
5
6
7
def get_text_size(
    text: str,
    fontsize: int | None = None,
    family: str | None = None,
    *,
    padding: int = 0,
) -> tuple[int, int]: ...

Get the size of a text with a special font family and font size

  • text: the text
  • fontsize: font size of the text
  • family: font family of the text
  • padding: extra padding of the size

ATTENTION:

  • This function only works when the fontsize is negative number!
  • When there is a line break, the return value will be inaccurate!

🔵load_font

function public

1
2
3
4
5
6
def load_font(
    font_path: str | bytes,
    *,
    private: bool = True,
    enumerable: bool = False,
) -> bool: ...

Make fonts located in file font_path available to the font system, and return True if the operation succeeds, False otherwise

  • font_path: the font file path
  • private: if True, other processes cannot see this font(Only Windows OS), and this font will be unloaded when the process dies
  • enumerable: if True, this font will appear when enumerating fonts(Only Windows OS)

ATTENTION:

  • This function is referenced from customtkinter.FontManager.load_font, CustomTkinter: TomSchimansky/CustomTkinter
  • This function only works on Windows and Linux OS

🔵screen_size

function public

def screen_size(
) -> tuple[int, int]: ...
Return the size of the screen

🔵set_mouse_position

function public

1
2
3
4
def set_mouse_position(
    x: int,
    y: int,
) -> None: ...

Set mouse cursor position

ATTENTION:

This function only works on Windows OS!

🟣_LINUX_FONTS_DIR

constant protected

_LINUX_FONTS_DIR: str = 'C:\\Users\\Yzk/.fonts/'