1

I have this code and focus dont work with customtkinter

from tkinter import *
import customtkinter as ctk
import sys

if len(sys.argv) > 1:
    print("Tk Customized from Tom")
    win = ctk.CTk()
    win.geometry("750x250")
    text = ctk.CTkTextbox(win, width=200, height=200)
    text.pack()
    text.insert(INSERT, "Hello World!")
    entry = ctk.CTkEntry(win, width=100)
    entry.pack()
    entry.focus_set()
else:
    print("Standard Tk ")
    win = Tk()
    win.geometry("750x250")
    text = Text(win, width=30, height=10)
    text.insert(INSERT, "Hello World!")
    text.pack()
    entry = Entry(win, width=30)
    entry.pack()
    entry.focus_set()

win.mainloop()

py testy.py -> Start standard Tkinter Focus is on Entry

py testy.py 1 -> Start with customtkinter objects Focus is NOT on Entry

How can get focus on CTkEntry ?

Rick
  • 92
  • 6
  • It may be issue on `customtkinter`. `focus_set()` works fine on `CTkEntry` after the window is visible. So you can delay the calling `focus_set()` a bit using `.after()`: `entry.after(10, entry.focus_set)`. – acw1668 Dec 12 '22 at 15:32
  • Hi acw1668, thank you for work around, it work fine ! – Rick Dec 14 '22 at 08:40

0 Answers0