Skip to content

Commit

Permalink
fix: Fix a bug where style switch of containers.Tk does not automat…
Browse files Browse the repository at this point in the history
…ically take effect on child windows

style: Improve some codes
  • Loading branch information
Xiaokang2022 committed Jan 7, 2025
1 parent fb89935 commit 5cc9dab
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tkintertools/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import platform
import tkinter
import tkinter.font
import traceback
import typing

import typing_extensions
Expand Down Expand Up @@ -179,9 +180,10 @@ def theme(
manager.apply_theme(self, theme="dark" if dark else "normal")

if include_children:
for child in self.children:
for child in self.children.values():
if isinstance(child, Toplevel):
child.theme(dark, include_canvases=include_canvases)
child.theme(dark, include_canvases=include_canvases,
include_children=True)

if include_canvases:
for canvas in self.canvases:
Expand Down Expand Up @@ -291,15 +293,16 @@ def at_exit(
* `ensure_destroy`: whether the window is guaranteed to be closed
"""
def wrapper() -> None:
try: # There is no need to catch errors
try:
command()
except Exception as exc: # pylint: disable=W0718
traceback.print_exception(exc)
finally:
if ensure_destroy:
self.destroy()

self.wm_protocol("WM_DELETE_WINDOW", wrapper)


class Toplevel(tkinter.Toplevel, Tk, Misc):
"""Toplevel window.
Expand Down Expand Up @@ -486,7 +489,6 @@ def _initialization(self) -> None:
case "s": dx, dy = self.init_size[0], self.init_size[1]//2
case "se": dx, dy = self.init_size[0], self.init_size[1]
case "center": dx, dy = self.init_size[0]//2, self.init_size[1]//2
case _: dx, dy = 0, 0

self.init_position = self.winfo_x() + dx, self.winfo_y() + dy
self._position = self.init_position
Expand Down

0 comments on commit 5cc9dab

Please sign in to comment.