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

时间:2014-10-27 09:13:55

标签: python button tkinter focus python-3.4

我想打开一个焦点设置为第一个按钮的窗口,所以我没有标签 如果小部件是Entry小部件,我可以写

widget_name.focus()

按钮小部件似乎没有等价物。

2 个答案:

答案 0 :(得分:1)

如果你正在使用Tkinter:

buttonname.focus_set()

答案 1 :(得分: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?