Disable focus for tkinter widgets? Disable focus for tkinter widgets? tkinter tkinter

Disable focus for tkinter widgets?


I have found some time to provide a working example:

import tkinterroot = 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.


I'm aware that this is an old question, but for any future readers, a simpler way to remove cycling focus for widgets is by unbinding <<NextWindow>>, as stated by Bryan Oakley here in this post.

import tkinter as tkroot = tk.Tk()button1 = tk.Button(root, text='Hello')  # Two example buttonsbutton2 = tk.Button(root, text='World!')button1.pack(ipadx=15, ipady=10)button2.pack(ipadx=10, ipady=10)root.unbind_all('<<NextWindow>>')  # Unbinding the behavior that causes Tab Cyclingroot.mainloop()

This will disable Cycling all widgets with Tab, if you would want to remove cycling focus for a single widget, setting -takefocus to 0 would be easier