# ctk_toggle: CustomTkinter Toggle Buttons and Groups
## Overview
`ctk_toggle` is a lightweight Python package for creating toggle buttons and groups using CustomTkinter.
## Features
- Create toggle buttons with customizable states.
- Group buttons for coordinated toggling.
- Easily manage toggle states programmatically.
## Installation
Install via pip:
```bash
pip install ctk_toggle
```
## Usage
Import modules:
```python
from ctk_toggle import CTkToggleButton, CTkToggleGroup
```
Check the [examples/](https://github.com/DeltaGa/ctk_toggle/tree/main/examples) directory for usage examples.
## Contributing
See [CONTRIBUTING.md](https://github.com/DeltaGa/ctk_toggle/blob/main/CONTRIBUTING.md).
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/DeltaGa/ctk_toggle/blob/main/LICENSE) file for details.
## Documentation
**CTkToggleGroup**
```python
class CTkToggleGroup:
"""
A group for managing toggle buttons.
"""
def __init__(self, buttons: Optional[List[CTkToggleButton]] = None, disable_color: str = "lightgrey"):
"""
Initialize a CTkToggleGroup.
Args:
buttons (Optional[List[CTkToggleButton]]): List of buttons in the group.
disable_color (str): Color for disabled buttons.
Raises:
TypeError: If buttons is not a list of CTkToggleButton instances or None.
ValueError: If disable_color is not a string.
"""
def add_button(self, button: CTkToggleButton):
"""
Add a button to the group.
Args:
button (CTkToggleButton): The button to add.
Raises:
TypeError: If button is not an instance of CTkToggleButton.
"""
def remove_button(self, button: CTkToggleButton):
"""
Remove a button from the group.
Args:
button (CTkToggleButton): The button to remove.
Raises:
TypeError: If button is not an instance of CTkToggleButton.
"""
def set_active_button(self, button: CTkToggleButton):
"""
Activate a specific button.
Args:
button (CTkToggleButton): The button to activate.
Raises:
TypeError: If button is not an instance of CTkToggleButton.
"""
def deactivate_all(self):
"""
Deactivate all buttons in the group.
"""
def get_active_button(self) -> Optional[CTkToggleButton]:
"""
Get the currently active button, if any.
Returns:
Optional[CTkToggleButton]: The currently active button, or None if no button is active.
"""
def _update_buttons(self):
"""
Update all buttons when one is disabled.
"""
def _configure_button(self, button: CTkToggleButton):
"""
Configure a button for the group.
Args:
button (CTkToggleButton): The button to configure.
Raises:
TypeError: If button is not an instance of CTkToggleButton.
"""
def _handle_button_toggle(self, button: CTkToggleButton):
"""
Handle toggle logic for a button.
Args:
button (CTkToggleButton): The button that was toggled.
Raises:
TypeError: If button is not an instance of CTkToggleButton.
"""
```
**CTkToggleButton**
```python
class CTkToggleButton(ctk.CTkButton):
"""
A CustomTkinter button with toggle functionality.
"""
def __init__(
self,
master=None,
toggle_color: str = "#c1e2c5",
disable_color: str = "lightgrey",
toggle_group: Optional[Any] = None,
**kwargs,
):
"""
Initialize a CTkToggleButton with toggle functionality.
Args:
master: Parent widget.
toggle_color (str): Color when toggled.
disable_color (str): Color when disabled.
toggle_group (Optional[CTkToggleGroup]): Group to coordinate toggling.
**kwargs: Additional keyword arguments for CTkButton.
Raises:
ValueError: If toggle_color or disable_color is not a string.
TypeError: If toggle_group is not an instance of CTkToggleGroup or None.
"""
def toggle(self, event=None):
"""
Handle button toggle behavior.
Args:
event: The event that triggered the toggle.
Raises:
RuntimeError: If the button is in an invalid state.
"""
def set_toggle_state(self, state: bool):
"""
Set the toggle state and update appearance.
Args:
state (bool): The new toggle state.
Raises:
ValueError: If state is not a boolean.
"""
def get_toggle_state(self) -> bool:
"""
Get the current toggle state.
Returns:
bool: The current toggle state.
Raises:
RuntimeError: If the button is in an invalid state.
"""
def enable(self):
"""
Enable the button.
Raises:
RuntimeError: If the button is already enabled.
"""
def disable(self):
"""
Disable the button.
Raises:
RuntimeError: If the button is already disabled.
"""
def _update_fg_color(self):
"""
Update the foreground color based on the toggle state.
"""
```
## Credits
### Author
- **Tchicdje Kouojip Joram Smith (DeltaGa)**
Creator and developer of the CTkToggleButton and CTkToggleGroup classes.
Email: dev.github.tkjoramsmith@outlook.com
GitHub: [https://github.com/DeltaGa](https://github.com/DeltaGa)
### Acknowledgments
- **CustomTkinter**: The CustomTkinter library provided the foundation for building modern and customizable widgets in this project.
GitHub: [https://github.com/TomSchimansky/CustomTkinter](https://github.com/TomSchimansky/CustomTkinter)
- **Open Source Community**: Inspiration and guidance from various open-source contributions and community members.
- **Python Community**: For creating an ever-evolving ecosystem that empowers developers worldwide.
### Contributions from Large Language Models
This project was developed with support and inspiration from state-of-the-art Large Language Models (LLMs), including but not limited to open/free-to-use models such as:
- OpenAI's GPT series.
- Open-source language models provided by communities like Hugging Face and EleutherAI.
These models were instrumental in providing guidance, code refactoring suggestions, and improving the overall quality of the project documentation. Special thanks to the developers, researchers, and communities who have contributed to the field of natural language processing and made these models publicly available for everyone.
The integration of such tools demonstrates how artificial intelligence can augment human creativity and productivity in software development and beyond.
Raw data
{
"_id": null,
"home_page": "https://github.com/DeltaGa/ctk_toggle",
"name": "ctk-toggle",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "customtkinter tkinter toggle button UI",
"author": "Tchicdje Kouojip Joram Smith (DeltaGa)",
"author_email": "dev.github.tkjoramsmith@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/4c/3d/3186997c94e603eb2949f5411464bcc7d1740d99ddf1fa972f7dc33173c4/ctk_toggle-1.0.1.tar.gz",
"platform": null,
"description": "# ctk_toggle: CustomTkinter Toggle Buttons and Groups\n\n## Overview\n`ctk_toggle` is a lightweight Python package for creating toggle buttons and groups using CustomTkinter.\n\n## Features\n- Create toggle buttons with customizable states.\n- Group buttons for coordinated toggling.\n- Easily manage toggle states programmatically.\n\n## Installation\nInstall via pip:\n```bash\npip install ctk_toggle\n```\n## Usage\nImport modules:\n```python\nfrom ctk_toggle import CTkToggleButton, CTkToggleGroup\n```\nCheck the [examples/](https://github.com/DeltaGa/ctk_toggle/tree/main/examples) directory for usage examples.\n\n## Contributing\nSee [CONTRIBUTING.md](https://github.com/DeltaGa/ctk_toggle/blob/main/CONTRIBUTING.md).\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/DeltaGa/ctk_toggle/blob/main/LICENSE) file for details.\n\n## Documentation\n**CTkToggleGroup**\n```python\nclass CTkToggleGroup:\n \"\"\"\n A group for managing toggle buttons.\n \"\"\"\n\n def __init__(self, buttons: Optional[List[CTkToggleButton]] = None, disable_color: str = \"lightgrey\"):\n \"\"\"\n Initialize a CTkToggleGroup.\n\n Args:\n buttons (Optional[List[CTkToggleButton]]): List of buttons in the group.\n disable_color (str): Color for disabled buttons.\n \n Raises:\n TypeError: If buttons is not a list of CTkToggleButton instances or None.\n ValueError: If disable_color is not a string.\n \"\"\"\n\n def add_button(self, button: CTkToggleButton):\n \"\"\"\n Add a button to the group.\n\n Args:\n button (CTkToggleButton): The button to add.\n \n Raises:\n TypeError: If button is not an instance of CTkToggleButton.\n \"\"\"\n\n def remove_button(self, button: CTkToggleButton):\n \"\"\"\n Remove a button from the group.\n\n Args:\n button (CTkToggleButton): The button to remove.\n \n Raises:\n TypeError: If button is not an instance of CTkToggleButton.\n \"\"\"\n\n def set_active_button(self, button: CTkToggleButton):\n \"\"\"\n Activate a specific button.\n\n Args:\n button (CTkToggleButton): The button to activate.\n \n Raises:\n TypeError: If button is not an instance of CTkToggleButton.\n \"\"\"\n\n def deactivate_all(self):\n \"\"\"\n Deactivate all buttons in the group.\n \"\"\"\n\n def get_active_button(self) -> Optional[CTkToggleButton]:\n \"\"\"\n Get the currently active button, if any.\n\n Returns:\n Optional[CTkToggleButton]: The currently active button, or None if no button is active.\n \"\"\"\n\n def _update_buttons(self):\n \"\"\"\n Update all buttons when one is disabled.\n \"\"\"\n\n def _configure_button(self, button: CTkToggleButton):\n \"\"\"\n Configure a button for the group.\n\n Args:\n button (CTkToggleButton): The button to configure.\n \n Raises:\n TypeError: If button is not an instance of CTkToggleButton.\n \"\"\"\n\n def _handle_button_toggle(self, button: CTkToggleButton):\n \"\"\"\n Handle toggle logic for a button.\n\n Args:\n button (CTkToggleButton): The button that was toggled.\n \n Raises:\n TypeError: If button is not an instance of CTkToggleButton.\n \"\"\"\n```\n\n**CTkToggleButton**\n```python\nclass CTkToggleButton(ctk.CTkButton):\n \"\"\"\n A CustomTkinter button with toggle functionality.\n \"\"\"\n\n def __init__(\n self,\n master=None,\n toggle_color: str = \"#c1e2c5\",\n disable_color: str = \"lightgrey\",\n toggle_group: Optional[Any] = None,\n **kwargs,\n ):\n \"\"\"\n Initialize a CTkToggleButton with toggle functionality.\n\n Args:\n master: Parent widget.\n toggle_color (str): Color when toggled.\n disable_color (str): Color when disabled.\n toggle_group (Optional[CTkToggleGroup]): Group to coordinate toggling.\n **kwargs: Additional keyword arguments for CTkButton.\n \n Raises:\n ValueError: If toggle_color or disable_color is not a string.\n TypeError: If toggle_group is not an instance of CTkToggleGroup or None.\n \"\"\"\n\n def toggle(self, event=None):\n \"\"\"\n Handle button toggle behavior.\n\n Args:\n event: The event that triggered the toggle.\n \n Raises:\n RuntimeError: If the button is in an invalid state.\n \"\"\"\n\n def set_toggle_state(self, state: bool):\n \"\"\"\n Set the toggle state and update appearance.\n\n Args:\n state (bool): The new toggle state.\n \n Raises:\n ValueError: If state is not a boolean.\n \"\"\"\n\n def get_toggle_state(self) -> bool:\n \"\"\"\n Get the current toggle state.\n\n Returns:\n bool: The current toggle state.\n \n Raises:\n RuntimeError: If the button is in an invalid state.\n \"\"\"\n\n def enable(self):\n \"\"\"\n Enable the button.\n \n Raises:\n RuntimeError: If the button is already enabled.\n \"\"\"\n\n def disable(self):\n \"\"\"\n Disable the button.\n \n Raises:\n RuntimeError: If the button is already disabled.\n \"\"\"\n\n def _update_fg_color(self):\n \"\"\"\n Update the foreground color based on the toggle state.\n \"\"\"\n```\n\n## Credits\n\n### Author\n- **Tchicdje Kouojip Joram Smith (DeltaGa)** \n Creator and developer of the CTkToggleButton and CTkToggleGroup classes. \n \n Email: dev.github.tkjoramsmith@outlook.com\n GitHub: [https://github.com/DeltaGa](https://github.com/DeltaGa)\n\n### Acknowledgments\n- **CustomTkinter**: The CustomTkinter library provided the foundation for building modern and customizable widgets in this project. \n GitHub: [https://github.com/TomSchimansky/CustomTkinter](https://github.com/TomSchimansky/CustomTkinter)\n\n- **Open Source Community**: Inspiration and guidance from various open-source contributions and community members.\n\n- **Python Community**: For creating an ever-evolving ecosystem that empowers developers worldwide.\n\n### Contributions from Large Language Models\n\nThis project was developed with support and inspiration from state-of-the-art Large Language Models (LLMs), including but not limited to open/free-to-use models such as:\n\n- OpenAI's GPT series.\n- Open-source language models provided by communities like Hugging Face and EleutherAI.\n\nThese models were instrumental in providing guidance, code refactoring suggestions, and improving the overall quality of the project documentation. Special thanks to the developers, researchers, and communities who have contributed to the field of natural language processing and made these models publicly available for everyone.\n\nThe integration of such tools demonstrates how artificial intelligence can augment human creativity and productivity in software development and beyond.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A lightweight Python package for creating toggle buttons and groups using CustomTkinter.",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/DeltaGa/ctk_toggle"
},
"split_keywords": [
"customtkinter",
"tkinter",
"toggle",
"button",
"ui"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4262df2f195de38aad4f00eed47528201abdafd7c29540ab6996970936e2bac6",
"md5": "23fa232b64f82b666e27f21a94241e61",
"sha256": "c8ef79a57d387e4cda67325043f53e618f742d0f9e83ee6702159dcd922d0a4e"
},
"downloads": -1,
"filename": "ctk_toggle-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "23fa232b64f82b666e27f21a94241e61",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 6983,
"upload_time": "2025-01-09T05:31:46",
"upload_time_iso_8601": "2025-01-09T05:31:46.077528Z",
"url": "https://files.pythonhosted.org/packages/42/62/df2f195de38aad4f00eed47528201abdafd7c29540ab6996970936e2bac6/ctk_toggle-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4c3d3186997c94e603eb2949f5411464bcc7d1740d99ddf1fa972f7dc33173c4",
"md5": "794c0ad8ebcffcb4a4a565e7f3c02524",
"sha256": "f5a553cb6462ec60c778a563c6d2844c4480c70cf95168c36fa12f17ea8b25e6"
},
"downloads": -1,
"filename": "ctk_toggle-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "794c0ad8ebcffcb4a4a565e7f3c02524",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5492,
"upload_time": "2025-01-09T05:31:48",
"upload_time_iso_8601": "2025-01-09T05:31:48.347130Z",
"url": "https://files.pythonhosted.org/packages/4c/3d/3186997c94e603eb2949f5411464bcc7d1740d99ddf1fa972f7dc33173c4/ctk_toggle-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-09 05:31:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "DeltaGa",
"github_project": "ctk_toggle",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "customtkinter",
"specs": [
[
">=",
"5.1.0"
]
]
}
],
"lcname": "ctk-toggle"
}