tkinter-toggle
A tkinter toggle widget is a reusable UI component that lets users instantly switch between two states (like On/Off) by dynamically updating the UI and executing code upon interaction.
Installation
It is recommended to install Python packages inside a virtual environment to prevent dependency conflicts.
1. Create and activate a virtual environment (Optional but recommended):
# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activate
2. Install the package:
pip install tkinter-toggle
Quick Start
Import the toggle widget and attach it to your Tkinter window. Don't forget to call .pack(), .grid(), or .place() to display it!
import tkinter as tk
from tkinter_toggle import tkToggle
def on_click(event):
print(event.value)
root = tk.Tk()
# Create the instance
toggle = tkToggle(root, default=False, size=30, bg="red", command=on_click)
# Show the toggle widget on the window
toggle.pack()
root.mainloop()
Configuration
When initializing tkToggle(master, ...), you can pass several optional arguments to customize its behavior and appearance.
Arguments
| Argument | Type | Default | Optional | Description |
|---|---|---|---|---|
default |
bool |
False |
Yes | The initial state or value of the toggle widget. |
size |
int |
20 |
Yes | The dimensions (width/height) of the widget. |
bg |
str |
"#0000ff" |
Yes | Background color (hex code or Tkinter color name). |
fg |
str |
"#ffffff" |
Yes | Thumb color (hex code or Tkinter color name). |
off_bg |
str |
"#aaaaaa" |
Yes | Toggle off background color (hex code or Tkinter color name). |
off_fg |
str |
same as fg |
Yes | Toggle off Thumb color (hex code or Tkinter color name). |
command |
Callable |
"" |
Yes | Function to execute when the user interacted with toggle widget. |
Note: The first argument must always be the parent window or frame (master).
Methods
Once initialized, you can interact with the widget programmatically using its built-in methods:
set_value(value: bool): Updates the current state of the toggle widget to the given boolean value.get_value() -> bool: Returns the current state of the toggle widget.toggle(): Reverse the current state of the toggle widget.config(bg: String = None, size: int = None, command: Callable = None): Modify size, background or command (function to invoke when the widget action occurs) of the toggle widget.
Full Example
Here is a complete working example. You can also view this code directly in the repository at tests/example.py.
import tkinter as tk
from tkinter_toggle import tkToggle
def on_click(event):
print(event.value)
# Initialize the main window
root = tk.Tk()
root.geometry("300x200+100+100")
root.title("Toggle Demo")
# Create and configure the widget
toggle = tkToggle(
root,
default=False,
size=30,
bg="green",
command=on_click
)
# Display the toggle widget
toggle.pack(pady=20)
# Modify the value programmatically
toggle.toggle()
# Configure this toggle widget
toggle.config(bg="blue", size=50)
# Run the application
root.mainloop()
PyPI Project
The official package registry, release history, and download statistics are available on the Python Package Index (PyPI):
https://pypi.org/project/tkinter-toggle/
License
This project is licensed under the GNU Lesser General Public License (LGPL). See the COPYING.LESSER and COPYING files for full details.
Metadata
Release files for tkinter-toggle 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tkinter_toggle-1.0.0.tar.gz | 17.6 kB | With provenance | Details for tkinter_toggle-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tkinter_toggle-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for tkinter_toggle-1.0.0-py3-none-any.whl |
Total release size: 36.4 kB
Release files / tkinter_toggle-1.0.0.tar.gz
| Download URL | tkinter_toggle-1.0.0.tar.gz |
|---|---|
| Size | 17.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e67ed6d03966e11ce567a491b28fa99da8683891e5550139a53af39de17b3e98
|
|
BLAKE2b-256 checksum How to use checksums |
46e1f794e1da865ab43c937e74e6d2a9b501bd7cd042f71d8d5939b322428793
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.
Transparency logRelease files / tkinter_toggle-1.0.0-py3-none-any.whl
| Download URL | tkinter_toggle-1.0.0-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72545ed204f826c7f1325b7cc99614798aa05c2a941b5c541abce945393d4322
|
|
BLAKE2b-256 checksum How to use checksums |
857227ed89a1e0edbb95eeed4799b4c26013c6a2c6c2904d6da8468a77ecc7a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.
Transparency logSecurity for tkinter-toggle 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for tkinter_toggle-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.