focus 和 focus_set 方法有什么区别?

What is the difference between focus and focus_set methods?

effbot.org website, there's a section talking about the Basic Widget Methods。其中两种方法是 focusfocus_set.

信不信由你,以下是我们在focus方法下找到的供参考:

The focus method.

而谈论 focus_set 方法的人说:

Moves the keyboard focus to this widget. This means that all keyboard events sent to the application will be routed to this widget.

我的问题是:这两种方法做同样的事情吗?如果不是,focus 做什么?

是的,两者是一回事。准确地说,focusfocus_set的别名。您可以通过解释器中的快速测试看到这一点:

>>> import tkinter
>>> tkinter.Text.focus is tkinter.Text.focus_set # Same function object
True
>>>
>>> help(tkinter.Text.focus)
Help on function focus_set in module tkinter:

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.

>>>

请注意在 focus 上调用 help() 如何调出 focus_set 的文档。