CTkLabel with takefocus=True needs 2 Tab presses per move — focus stops on inner CTkCanvas

Open Beginner friendly
#2,803 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
desktop

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

bug

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

Image
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TomSchimansky/CustomTkinter

All issues in TomSchimansky/CustomTkinter

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.