Skip to content

Commit

Permalink
fix: Fix the bug that the state update of some widgets is misplaced
Browse files Browse the repository at this point in the history
fix: Fix a bug where nested widgets can not be deleted correctly
  • Loading branch information
Xiaokang2022 committed Jan 10, 2025
1 parent 2e28218 commit 3ec3d3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tkintertools/core/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ def destroy(self) -> None:
self.master.canvases.remove(self)

for widget in tuple(self.widgets):
widget.destroy()
# Nested widget will be destroyed by its parent widget
if not widget.nested:
widget.destroy()

return tkinter.Canvas.destroy(self)

Expand Down
10 changes: 7 additions & 3 deletions tkintertools/standard/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def set(self, value: bool, *, callback: bool = False) -> None:
self.feature.command(value)
if self.get() == bool(value):
return
self.update(f"{self.state.split('-', maxsplit=1)}-{'on' if value else 'off'}", gradient_animation=True)
self.update(f"{self.state.split('-', maxsplit=1)[0]}-{'on' if value else 'off'}")
dx = self.shapes[0].size[0]/2 if value else -self.shapes[0].size[0]/2
animations.MoveElement(
self.shapes[1], (dx, 0), 250, controller=controllers.smooth, fps=60).start()
Expand Down Expand Up @@ -526,7 +526,7 @@ def set(self, value: bool, *, callback: bool = False) -> None:
self.feature.command(value)
if self.get() == bool(value):
return None
self.update(f"{self.state.split('-', maxsplit=1)}-{'on' if value else 'off'}")
self.update(f"{self.state.split('-', maxsplit=1)[0]}-{'on' if value else 'off'}")


class ToggleButton(virtual.Widget):
Expand Down Expand Up @@ -611,7 +611,7 @@ def set(self, value: bool, *, callback: bool = False) -> None:
self.feature.command(value)
if self.get() == bool(value):
return
self.update(f"{self.state.split('-', maxsplit=1)}-{'on' if value else 'off'}")
self.update(f"{self.state.split('-', maxsplit=1)[0]}-{'on' if value else 'off'}")


class RadioBox(virtual.Widget):
Expand Down Expand Up @@ -1179,6 +1179,7 @@ def __init__(
placeholder: str = "",
show: str | None = None,
limit: int = math.inf,
default: str | None = None,
command: collections.abc.Callable[[bool], typing.Any] | None = None,
image: enhanced.PhotoImage | None = None,
name: str | None = None,
Expand All @@ -1204,6 +1205,7 @@ def __init__(
* `show`: display a value that obscures the original content
* `placeholder`: a placeholder for the prompt
* `limit`: limit on the number of characters
* `default`: default value of the widget
* `command`: a function that is triggered when the button is pressed
* `image`: image of the widget
* `name`: name of the widget
Expand Down Expand Up @@ -1236,6 +1238,8 @@ def __init__(
self.format = format_spec
self.step = step
self.feature = features.SpinBoxFeature(self, command=command)
if default is not None:
self.set(default)

def change(self, up: bool) -> None:
"""Try change the current value"""
Expand Down

0 comments on commit 3ec3d3e

Please sign in to comment.