A tkinter toggle widget is a reusable UI component for tkinter application.
Project description
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). |
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.
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()
# Run the application
root.mainloop()
License
This project is licensed under the GNU Lesser General Public License (LGPL). See the COPYING.LESSER and COPYING files for full details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tkinter_toggle-0.1.0.tar.gz.
File metadata
- Download URL: tkinter_toggle-0.1.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d53cf79585b301d9e6af1e3971d4837df2d583764369758a345f3e34ae439662
|
|
| MD5 |
e701b99d563e015335cfec268cb0cf0a
|
|
| BLAKE2b-256 |
fa8daa669f3c195fc68e170f155f70e82aa739b5dc044361074ee551aebe052f
|
Provenance
The following attestation bundles were made for tkinter_toggle-0.1.0.tar.gz:
Publisher:
publish.yml on akarshit-1609/tkinter-toggle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tkinter_toggle-0.1.0.tar.gz -
Subject digest:
d53cf79585b301d9e6af1e3971d4837df2d583764369758a345f3e34ae439662 - Sigstore transparency entry: 2205326198
- Sigstore integration time:
-
Permalink:
akarshit-1609/tkinter-toggle@35d72ab3f4f299b6b4f2c0245549e09a81f152de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/akarshit-1609
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@35d72ab3f4f299b6b4f2c0245549e09a81f152de -
Trigger Event:
push
-
Statement type:
File details
Details for the file tkinter_toggle-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tkinter_toggle-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21610f8ff63bdd0071e0e1061dce031d1c7fea21ded43ee1fb481323e1ed67fd
|
|
| MD5 |
b554d14d812773f9e4705141b1941c7f
|
|
| BLAKE2b-256 |
45fc7371dc3ef2c851b9e350238fca50c87d0f9d6407d1763d5cb3b5e798ca1d
|
Provenance
The following attestation bundles were made for tkinter_toggle-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on akarshit-1609/tkinter-toggle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tkinter_toggle-0.1.0-py3-none-any.whl -
Subject digest:
21610f8ff63bdd0071e0e1061dce031d1c7fea21ded43ee1fb481323e1ed67fd - Sigstore transparency entry: 2205326217
- Sigstore integration time:
-
Permalink:
akarshit-1609/tkinter-toggle@35d72ab3f4f299b6b4f2c0245549e09a81f152de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/akarshit-1609
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@35d72ab3f4f299b6b4f2c0245549e09a81f152de -
Trigger Event:
push
-
Statement type: