Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python focus和focus\u set方法之间的区别是什么?_Python_Python 3.x_Tkinter_Focus - Fatal编程技术网

Python focus和focus\u set方法之间的区别是什么?

Python focus和focus\u set方法之间的区别是什么?,python,python-3.x,tkinter,focus,Python,Python 3.x,Tkinter,Focus,在这个网站上,有一个部分讨论了这个问题。其中两种方法是focus和focus\u set 信不信由你,以下是我们在该方法下的参考: 焦点法 而一位谈论这种方法的人说: 将键盘焦点移动到此小部件。这意味着所有的键盘 发送到应用程序的事件将路由到此小部件 我的问题是:这两种方法做同样的事情吗?如果不是,那么焦点是什么?是的,两者是一样的。准确地说,focus是focus\u set的别名。您可以从解释器中的快速测试中看到这一点: >>> import tkinter >>

在这个网站上,有一个部分讨论了这个问题。其中两种方法是
focus
focus\u set

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

焦点法

而一位谈论这种方法的人说:

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


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

是的,两者是一样的。准确地说,
focus
focus\u 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\u集的文档。为什么tkinter方法有别名?这不是我第一次发现这样的情况……我想只有Tkinter开发人员才能回答这个问题特金特图书馆总是显得有点臃肿。如果我不得不猜测的话,它要么是1)像其他GUI工具包那样,学习曲线更小,要么是2)更方便(如果你能想到的话,Tkinter有它)。@Rinzler我的猜测是,
focus\u set
是从tcl命令派生的,
focus
是“更友好、更具pythonic”的版本。我不知道是谁先加的。我同意复制有点烦人,但弃用和删除并不容易。@Rinzler-每次安装Python时附带的Python IDE完全是用Python和Tkinter编写的。您可以在标准库中的
Lib/idlelib
@iCodez下找到源代码是的,我知道,但是它很复杂,有很多文件。。。你认识其他人吗?