focus和focus_set方法之间有什么区别?

nbr*_*bro 5 python focus tkinter python-3.x

effbot.org网站上,有一节讨论“ 基本小部件方法”。其中两种方法是focusfocus_set

信不信由你,以下是我们在该focus方法下可以参考的内容:

聚焦方法。

一位谈论该focus_set方法的人说:

将键盘焦点移至此小部件。这意味着发送到应用程序的所有键盘事件都将路由到此小部件。

我的问题是:这两种方法做同一件事吗?如果没有,该怎么focus办?

iCo*_*dez 6

是的,两者是同一回事。确切地说,focus是的别名focus_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.

>>>
Run Code Online (Sandbox Code Playgroud)

请注意如何调用help()focus拉起的文档focus_set