Search code examples
pythontkintertextboxcustomtkintertab-ordering

How to adjust the tab order in CustomTkinter Textbox widget


I wanted to set the focus on the entry widget when the Tab key is pressed, but nothing happens.

import customtkinter as ctk

def tab(event):
    entry.focus_force()

main = ctk.CTk()
main.geometry()

textbox = ctk.CTkTextbox(main)
textbox.pack(pady=10)
entry = ctk.CTkEntry(main)
entry.pack(pady=10)

textbox.bind("<Tab>", tab)
main.mainloop()

I've tried this with other widgets and it worked, but it didn't work with the textbox.


Solution

  • You need to return "break" to disable default handling for the tab key inside tab():

    def tab(event)
        entry.focus_force()
        return "break"