Search code examples
pythonmacostkinter

Python Tkinter Entry.focus() doesn't work


I have problem with Tkinter on macOS system with many things, and one of them is the method .focus() doesn't work, despite I do according to a guide from Udemy and the author has macOS to.

So I tried to put in the focus Entry from Tkinter. I've done it in two ways, because there people how tall is the .focus() has to be before .grid(), but in video .focus() was after .grid(). In both cases, it doesn't work.

Has someone have this problem?

enter image description here

enter image description here


Solution

  • You can use website_input.focus() or website_input.focus_set(). Once u already had problem with .focus(), can you try focus_set(). I have tested both function in below code and both are worked well.

    from tkinter import *
    
    root = Tk()
    
    root.geometry("750x250")
    
    entry= Entry(root, width= 25)
    entry.focus()
    
    entry.pack()
    
    #or entry.focus_set()
    
    
    root.mainloop()