Skip to content

Restores Tk-compatible bg and background aliases for CTk.configure#16

Open
ajkessel wants to merge 2 commits into
FedericoSpada:masterfrom
ajkessel:fix-ctk-bg-alias
Open

Restores Tk-compatible bg and background aliases for CTk.configure#16
ajkessel wants to merge 2 commits into
FedericoSpada:masterfrom
ajkessel:fix-ctk-bg-alias

Conversation

@ajkessel

@ajkessel ajkessel commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

I've started running this code through updated unit tests based on my https://github.com/ajkessel/Custom2kinter/tree/m1-test-foundation branch. I will eventually propose those branch as a PR, but first I wanted to get some fixes through that the unit tests have surfaced.

This PR restores Tk-compatible bg and background aliases for CTk.configure(). These now route through the existing fg_color handling path, so cget("fg_color"), cget("bg"), appearance-mode color application, and child color propagation stay consistent.

@ajkessel ajkessel marked this pull request as ready for review June 30, 2026 14:14
@FedericoSpada

Copy link
Copy Markdown
Owner

Why would you need this?
bg and background are not valid arguments (they are not present in ValidTkArgs). In CustomTkinter, "fg_color" is the chosen name to refer to the primary color of all widgets. You also risk confusing it with "bg_color".
Moreover, other widgets also have the "bg"/"background" attribute, but it has been renamed "fg_color".

cget("bg") allows you to retrieve the currently displayed color, taking appearance_mode into account, but this is more a side effect of the implementation than an intended feature. configure(bg=...) should not be used and should result in a type-check failure.

When I moved the constructor arguments to dedicated TypedDict classes, I looked for a way to specify that the cget() method can accept only keys of the TypedDict (something similar to Unpack, but for the keys only). Unfortunately, I didn't find a good solution that didn't require maintaining a separate Literal[...] type with all possible values.

@ajkessel

Copy link
Copy Markdown
Contributor Author

OK, that makes sense. I treated this as a compatibility regression because the legacy unit test from customtkinter used configure(bg=...) / configure(background=...), but your explanation clarifies that fg_color is the intended CustomTkinter API and that cget("bg") working is just an implementation detail.

I agree that adding bg / background to configure() would blur the distinction between fg_color and bg_color, and would also weaken the TypedDict argument checking.

I’ll close this PR shortly and update the pytest updates I'm working through to stop asserting configure(bg=...) support. The test should use configure(fg_color=...) for the supported public API, and avoid treating cget("bg") as a configurable round-trip contract.

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