开发者

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

开发者 https://www.devze.com 2023-02-18 13:24 出处:网络
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 withou

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 t开发者_C百科he 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. For example:

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

精彩评论

暂无评论...
验证码 换一张
取 消