In Tkinter how do i remove focus from a widget?

后端 未结 6 901
余生分开走
余生分开走 2021-02-08 13:37

I\'d like to remove focus from a widget manually.

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-08 14:15

    You can focus to another dummy widget.

    Edit

    from Tkinter import *
    
    def callback():
        print master.focus()
    
    master = Tk()
    e = Entry(master)
    e.pack()
    e.focus()
    b = Button(master, text="get", width=10, command=callback)
    b.pack()
    
    master.mainloop()
    

    Focusing on a non-'focusable' widget will remove focus from another widget.

提交回复
热议问题