Skip to content

Commit

Permalink
feat: Add methods get and set to some widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaokang2022 committed Jan 19, 2025
1 parent 3e49562 commit 44755d9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tkintertools/standard/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def __init__(
underline=underline, overstrike=overstrike, justify=justify)
self.feature = features.LabelFeature(self)

def get(self) -> str:
"""Get the text of the widget"""
return self.texts[0].get()

def set(self, text: str) -> None:
"""Set the text of the widget"""
return self.texts[0].set(text)


class Button(virtual.Widget):
"""Button widget, typically used to trigger a function"""
Expand Down Expand Up @@ -283,6 +291,14 @@ def __init__(
underline=underline, overstrike=overstrike, justify=justify)
self.feature = features.ButtonFeature(self, command=command)

def get(self) -> str:
"""Get the text of the widget"""
return self.texts[0].get()

def set(self, text: str) -> None:
"""Set the text of the widget"""
return self.texts[0].set(text)


class Switch(virtual.Widget):
"""Switch widget, typically used to control the turning of a function on and off"""
Expand Down Expand Up @@ -945,6 +961,14 @@ def __init__(
justify=justify, anchor="w")
self.feature = features.ButtonFeature(self, command=command)

def get(self) -> str:
"""Get the text of the widget"""
return self.texts[0].get()

def set(self, text: str) -> None:
"""Set the text of the widget"""
return self.texts[0].set(text)


class Slider(virtual.Widget):
"""A slider for visually resizing values"""
Expand Down Expand Up @@ -1618,6 +1642,14 @@ def __init__(
widget._update_hooks.append(self._display)
self.forget()

def get(self) -> str:
"""Get the text of the widget"""
return self.texts[0].get()

def set(self, text: str) -> None:
"""Set the text of the widget"""
return self.texts[0].set(text)

def _display(self, state: str | None, _: bool) -> None:
"""Show or hide the tooltip"""
if state is None:
Expand Down

0 comments on commit 44755d9

Please sign in to comment.