简体   繁体   English

如何将焦点放在python Tkinter文本小部件上?

[英]How do I give focus to a python Tkinter text widget?

I'd like to be able to open the App GUI and have it automatically place the cursor into a particular text widget. 我希望能够打开App GUI并让它自动将光标放入特定的文本小部件中。 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()

You use the focus_set method. 您使用focus_set方法。 For example: 例如:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Tkinter、Python 中的文本小部件中移除焦点 - How to remove focus out of a Text widget in Tkinter, Python 在 Tkinter 中,如何从小部件中移除焦点? - In Tkinter how do i remove focus from a widget? Tkinter,Python:如何保存在“输入”小部件中输入的文本? 如何移动标签? - Tkinter, Python: How do I save text entered in the Entry widget? How do I move a label? 如何获取Tkinter Text小部件中Text的当前长度 - How do I get the current length of the Text in a Tkinter Text widget Tkinter:如何隐藏文本,就像使用带有文本(而非输入)小部件的密码一样? - Tkinter: How do I hide text as if with a password with a Text (not Entry) widget? 如何在 Tkinter 文本小部件中居中文本? - How do I center text in the Tkinter Text widget? 在 Python Tkinter 中,如何使用名称获取嵌入在文本小部件中的图像的索引? - In Python Tkinter, how do I get the index of an image embedded in a text widget using the name? 在Python 2.6中使用Tkinter,如何使按钮小部件在文本框中打印出选中的Checkbuttons? - Using Tkinter in Python 2.6 how do I make a button widget print out selected Checkbuttons in a text box? 如何将用户输入放入文本小部件中并使用 Python 使用 tkinter 在日志文件中进行搜索 - How can I put user input inside text widget and do search in Log file with tkinter using Python Python Tkinter 在 MacOS 中的检查按钮小部件:如何设置文本颜色 - Python Tkinter checkbutton widget in MacOS: how do I set the text colour
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM