Search code examples
pythonbuttontkinterfocus

Disable focus for tkinter widgets?


How can I make a widget that will not get the focus ever in tkinter? For example, a button that when I will press TAB the focus will skip on him


Solution

  • I have found some time to provide a working example:

    import tkinter
    
    root = tkinter.Tk()
    
    but1 = tkinter.Button(root, text ="Button 1")
    but1.pack()
    
    butNoFocus = tkinter.Button(root, text ="Button no focus", takefocus = 0)
    butNoFocus.pack()
    
    but2 = tkinter.Button(root, text = "Button 2")
    but2.pack()
    
    root.mainloop()    
    

    The takefocus option set to 0 will disable tab focus on butNoFocus.