CTkLabel with takefocus=True needs 2 Tab presses per move — focus stops on inner CTkCanvas
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start in customtkinter/windows/widgets/ctk_label.py and inspect how self._canvas is constructed. Run the supplied two-label reproduction to confirm the intermediate canvas focus stop, then check whether other composite widgets show the same pattern. Done means Tab moves directly between the two CTkLabels with one press each.
Written by the indexing model from the issue text.
Description
When two CTkLabels share a parent and both have takefocus=True, Tab traversal doesn't go directly from one to the other — it makes an invisible stop on each label's internal CTkCanvas. So two Tab presses are needed for one visible move.
Reproduction
import customtkinter as ctk
def log(name):
return lambda e: print(f"[{name}] type={e.type} widget={str(e.widget).split('.')[-1]}")
root = ctk.CTk()
root.geometry("420x180")
a = ctk.CTkLabel(root, text="a", takefocus=True, fg_color=("#ddd", "#303030"),
width=240, height=36, corner_radius=6)
b = ctk.CTkLabel(root, text="b", takefocus=True, fg_color=("#ddd", "#303030"),
width=240, height=36, corner_radius=6)
a.pack(pady=6); b.pack(pady=6)
for w, n in ((a, "a"), (b, "b")):
w.bind("", log(n))
w.bind("", log(n))
root.after(200, a.focus_set)
root.mainloop()
Click the window, press Tab.
Actual
[a] type=10 widget=!label ← FocusOut from a
[b] type=9 widget=!ctkcanvas ← intermediate stop on canvas (Tab #1)
[b] type=10 widget=!ctkcanvas
[b] type=9 widget=!label ← finally on b (Tab #2)
Expected
[a] type=10 widget=!label
[b] type=9 widget=!label ← single press, single move
Cause
CTkLabel._canvas is a tkinter.Canvas subclass. Canvas's default takefocus="" defers to Tk's heuristic, which includes widgets with class-level key bindings — and Canvas does. So traversal walks through it before reaching the inner tk.Label.
Suggested fix
In customtkinter/windows/widgets/ctk_label.py, pass takefocus=0 to self._canvas at construction. Same pattern likely affects other composite widgets (CTkButton, CTkEntry, ...) — worth a sweep.
Workaround
label._canvas.configure(takefocus=0)
Note
Hit this while working on my own project — CTkMaker, a drag-and-drop designer for CustomTkinter. Patched locally with the workaround above; filing here so it can be fixed at the source.
ctk_label_focus_fixed.py
ctk_label_focus_buggy.py
- Dominant language
- Python
- Stars
- 13.6k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TomSchimansky/CustomTkinter
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TomSchimansky/CustomTkinter#2866 · 9 comments ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
TomSchimansky/CustomTkinter#2128 · 4 reactions ·
-
Glassmorphism Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
TomSchimansky/CustomTkinter#2864 · 1 comment ·
-
Can't Change WM_INFO Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
TomSchimansky/CustomTkinter#2859 · 8 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
TomSchimansky/CustomTkinter#2858 · 4 comments ·
All issues in TomSchimansky/CustomTkinter
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100