跳转至

maliang.toolbox

字数 11 个   阅读时间不到 1 分钟   访问量

源代码:maliang/toolbox/__init__.py

Some practical tools

模块:

  • enhanced

    Enhanced versions of some tkinter classes and functions.

  • utility

    Some useful utility classes or utility functions.

类:

  • PhotoImage

    Pillow version of tkinter.PhotoImage.

函数:

  • get_parent

    Get the HWND of tkinter.Widget.

  • embed_window

    Embed a widget into another widget.

  • load_font

    Make fonts located in file font_path available to the font system, and

  • screen_size

    Returns the size of the screen.

  • get_text_size

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

  • fix_cursor

    Fix the cursor name.

  • create_smoke

    Create a temporary smoke zone. Return the enhanced.PhotoImage.

PhotoImage

Bases: ImageTk.PhotoImage, tkinter.PhotoImage

Pillow version of tkinter.PhotoImage.

方法:

  • scale

    Scale the PhotoImage.

  • resize

    Resize the PhotoImage.

scale

scale(x: float, y: float) -> PhotoImage

Scale the PhotoImage.

  • x: The x-axis scale factor
  • y: The y-axis scale factor

resize

resize(width: int, height: int) -> PhotoImage

Resize the PhotoImage.

  • width: The new width of the image
  • height: The new height of the image

get_parent

get_parent(widget: tkinter.Misc) -> int

Get the HWND of tkinter.Widget.

  • widget: the widget

embed_window

embed_window(window: tkinter.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

load_font

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)

This function only works on Windows and Linux OS.

This function is referenced from customtkinter.FontManager.load_font, CustomTkinter: TomSchimansky/CustomTkinter.

screen_size

screen_size() -> tuple[int, int]

Returns the size of the screen.

get_text_size

get_text_size(
    text: str,
    fontsize: int | None = None,
    family: str | None = None,
    *,
    padding: int = 0,
    master: tkinter.Canvas | virtual.Widget | None = None,
    **kwargs
) -> 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
  • master: default canvas or widget provided
  • kwargs: kwargs of tkinter.font.Font

This function only works when the fontsize is negative number!

fix_cursor

fix_cursor(name: str) -> str

Fix the cursor name.

  • name: name of cursor

create_smoke

create_smoke(
    size: tuple[int, int], *, color: str | tuple[int, int, int, int] = "#00000066"
) -> enhanced.PhotoImage

Create a temporary smoke zone. Return the enhanced.PhotoImage.

  • size: size of the smoke zone
  • color: color of the smoke zone

This function need PIL to run.

About the “smoke”, see: https://fluent2.microsoft.design/material#smoke