如何将焦点放在 python Tkinter 文本小部件上? [英] How do I give focus to a python Tkinter text widget?

查看:37
本文介绍了如何将焦点放在 python Tkinter 文本小部件上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够打开应用程序 GUI 并让它自动将光标置于特定的文本小部件中.最好的情况是:一旦应用程序启动,某人就可以开始输入,而无需单击文本小部件.这只是一个显示问题的小例子:

I'd like to be able to open the App GUI and have it automatically place the cursor into a particular text widget. Best case scenario is: as soon as the app is launched someone can start typing without having to click on the text widget. This is just a small example displaying the issue:

from Tkinter import *
root = Tk()
Window = Frame(root)
TextWidget = Text(Window)
TextWidget.pack()
Window.pack()
root.mainloop()

推荐答案

您使用 focus_set 方法.例如:

You use the focus_set method. For example:

from Tkinter import *
root = Tk()
Window = Frame(root)
TextWidget = Text(Window)
TextWidget.pack()
Window.pack()
TextWidget.focus_set()
root.mainloop()

这篇关于如何将焦点放在 python Tkinter 文本小部件上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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