Skip to content

Commit

Permalink
feat: use the descriptor to get tkinter._default_root dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaokang2022 committed Nov 7, 2024
1 parent bcdf0c2 commit 53a9a12
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions tkintertools/core/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@
]


class _DefaultRoot:
"""A simple descriptor about tkinter._default_root."""

def __get__(self, obj, cls) -> tkinter.Tk | None:
"""Return the current default root."""
return tkinter._default_root


class Env:
"""Configurations of environment."""

system: str
is_dark: bool

default_root: tkinter.Tk | None
default_root: tkinter.Tk | None = _DefaultRoot()

@classmethod
def reset(cls) -> None:
Expand All @@ -50,16 +58,6 @@ def get_default_system() -> str:
return "Windows10"
return system

@typing_extensions.override
# @classmethod # XXX: Using this decorator will produce an error, strangely
def __getattr__(self, name: str) -> typing.Any:
if name == "default_root":
return tkinter._default_root
return super().__getattr__(name) # pylint: disable=no-member


Env = Env() # Camouflaged as a class to solve the strange problem above


class Font:
"""Configurations of font."""
Expand Down

0 comments on commit 53a9a12

Please sign in to comment.