[英]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.