在 Tkinter Python 中的条目小部件内设置默认插入符号位置 [英] Set default caret position inside entry widget in Tkinter Python

查看:63
本文介绍了在 Tkinter Python 中的条目小部件内设置默认插入符号位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行程序时在入口小部件内设置默认光标位置.

I want to set the default cursor location inside the entry widget when I run the program.

因此,当我运行它时,我不必在小部件内部单击即可开始输入.

So when I run it I don't have to click inside the widget to start typing.

谁能帮我解决这个问题?其实我是编程新手

Can anyone help me with this? Actually I'm new at programming

import tkinter as tk

root = tk.Tk()

e = tk.Entry(root)
e.pack()

tk.mainloop()

推荐答案

只需调用小部件的 focus 方法:

Simply call the focus method for the widget:

import tkinter as tk

root = tk.Tk()

e = tk.Entry(root)
e.pack()
e.focus()

tk.mainloop()

这篇关于在 Tkinter Python 中的条目小部件内设置默认插入符号位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆