Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 tkinter 页面,它会询问用户名和密码(为此使用了 2 个输入框)。我想要的是一旦用户运行脚本,光标应该在用户名字段(第一个输入框)中,以便用户可以输入用户名,而无需在输入前使用鼠标单击输入框。有什么办法吗?
您正在寻找的术语是“焦点”——焦点定义了哪个小部件处于活动状态并接受键盘事件。您可以在窗口可见之前设置焦点,当它变得可见时,它将获得焦点。
为此,您应该使用focus_set适用于每个小部件的方法:
focus_set
import Tkinter as tk ... entry1 = tk.Entry(...) entry1.focus_set()