当tkinter窗口失去可以使用tkinter方法绑定到tkinter窗口的焦点时,是否会触发某些事件?
发布于 2017-10-04 14:27:32
您要寻找的事件是<FocusOut>。
import tkinter as tk
def on_focus_out(event):
if event.widget == root:
label.configure(text="I DON'T have focus")
def on_focus_in(event):
if event.widget == root:
label.configure(text="I have focus")
root = tk.Tk()
label = tk.Label(width=30)
label.pack(side="top", fill="both", expand=True)
root.bind("<FocusIn>", on_focus_in)
root.bind("<FocusOut>", on_focus_out)
root.mainloop()https://stackoverflow.com/questions/46567324
复制相似问题