Tkinter将焦点放在Entry小部件上

时间:2014-03-04 02:40:23

标签: python tkinter widget setfocus tkinter-entry

这是我的代码:

import tkinter as tk
userData = tk.Tk()
nbdays = tk.IntVar()
mainframe = tk.Frame(userData, relief= 'raised', borderwidth=1)
tk.Label(mainframe, text = 'Number of days', font = 10).place(x=2, y = 30)
tk.Entry(mainframe, width= 8, textvariable = nbdays).place(x= 200, y= 30)

[...]

如何将焦点设置在最后一个tk.Entry(。)小部件上?

1 个答案:

答案 0 :(得分:13)

使用所有小部件通用的focus_set方法:

entry = tk.Entry(...)
entry.place(...)
entry.focus_set()