导入 _tkinter 还是 tkinter? [英] Import _tkinter or tkinter?
问题描述
所有教程只需import tkinter
,
我想知道,为什么不import _tkinter
?如果我的理解是正确的,_tkinter
是 cpython 中的实际库,而 tkinter
是接口或 API.
I am wondering, though, why not import _tkinter
? If my understanding is correct, _tkinter
is the actual library in cpython and tkinter
is the interface or API.
我只是在阅读一些 tkinter 源代码时试图掌握范式.似乎有一些蟒蛇黑魔法正在上演.
I am simply trying to grasp the paradigm as I read through some of the tkinter source code. It seems there is some python black magic afoot.
推荐答案
_tkinter
是一个基于 C 的模块,它封装了一个内部 tcl/tk 解释器.当你导入它时,并且只有它,你可以访问这个解释器但你不能访问任何 python 类.
_tkinter
is a C-based module that wraps an internal tcl/tk interpreter. When you import it, and it only, you get access to this interpreter but you do not get access to any of the python classes.
您当然可以导入 _tkinter
,但随后您必须重新创建 tcl/tk 函数的所有 python 接口.
You certainly can import _tkinter
, but then you would have to recreate all of the python interfaces to the tcl/tk functions.
这篇关于导入 _tkinter 还是 tkinter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!