如何使用tkinter将按钮设置为焦点?

3
我想打开一个窗口并将焦点设置在第一个按钮上,这样我就不必通过制表符到达它。
如果小部件是输入小部件,我可以编写
widget_name.focus()

似乎没有与按钮小部件相对应的等效物。


1
你使用的GUI包是什么? - Ffisegydd
2个回答

4

如果您正在使用Tkinter:

buttonname.focus_set()

0
在我看来,这似乎有一个对应之处。
tkinter.Button = class Button(Widget)
 |  Button widget.
 |  
 |  Method resolution order:
 |      Button
 |      Widget
 |      BaseWidget
 |      Misc
 |      Pack
 |      Place
 |      Grid
 |      builtins.object
 ...
 |  focus = focus_set(self)
 |      Direct input focus to this widget.
 |      
 |      If the application currently does not have the focus
 |      this widget will get the focus if the application gets
 |      the focus through the window manager.

而且在tkinter.py

class Misc:
    # ...
    focus = focus_set # XXX b/w compat?

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接