Skip to content

Conversation

@fredmain
Copy link

@fredmain fredmain commented May 4, 2025

Description

This pull request fixes an issue in the CTkSwitch widget where the onvalue and offvalue parameters could only be set during initialization, but not via the configure() method.

Trying to use .configure(onvalue=..., offvalue=...) would raise a ValueError due to missing handling for those parameters in the method.

Reproduction

import customtkinter

root = customtkinter.CTk()
s = customtkinter.CTkSwitch(root)
s.configure(onvalue='manual', offvalue='automatic')  # 💥 ValueError before this fix
s.pack()
root.mainloop()

Fix

I added handling for onvalue and offvalue inside the configure() method of CTkSwitch, following the same pattern used for other supported keyword arguments like text, state, and variable.
Let me know if I should add test cases or adjust anything.

@FedericoSpada
Copy link
Collaborator

Hi,
I like the idea, but you have to update also the _check_state attribute when you change "onvalue" and "offvalue". Moreover, you need to set "require_redraw = True" so that the widget is updated.
You can copy what has been done to update "variable".

Finally, could you please move your code between "textvariable" and "variable" if statements, so that similar code blocks are near each other.
Thanks.

FedericoSpada added a commit that referenced this pull request Jan 13, 2026
- Added missing attributes to the configure() method for all widgets.
- Allowed changing a CTkButton image using configure even if the widget was created without any image.
- Prevented warning when an image is set to "" with configure() to delete it.
- Fixed CTkCheckbox hover_color for the blue theme, which was hiding the hover effect when checked.
Fixes #1215, #1750, #2494 and replaces #2412, #2719

Co-Authored-By: Shubham25dec <[email protected]>
Co-Authored-By: fred Jose Diaz <[email protected]>
@FedericoSpada
Copy link
Collaborator

I've replicated the same changes together with an overall configure() clean-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants