“tk.call"有什么作用?函数在 Python/Tkinter 中做什么? [英] What does the "tk.call" function do in Python/Tkinter?

查看:49
本文介绍了“tk.call"有什么作用?函数在 Python/Tkinter 中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过 Python 脚本中的调用函数,称为tk.call(),但我不明白相同的含义.也没有与之相关的文档.

I have seen call function in Python scripts, called as tk.call(), but I don't understand the meaning of the same. There is no documentation related to it too.

谁能解释一下call()函数的功能.

Can any one please explain about the functionality of call() function.

这是一个简单的例子:

p.tk.call(p, 'put', color, '-to', 0, 0, p['width'], p['height']) 

这个函数的功能,其中pPhotoImage小部件.

The functionality of this function, where p is the PhotoImage widget.

推荐答案

Tkinter 不是纯 Python.它的底层是一个实时的 Tcl 解释器,其中一个名为tk"的扩展名加载到解释器中.大多数 Tkinter 命令、方法和对象最终都会调用 tcl 命令.例如,当您执行以下操作时:

Tkinter isn't pure python. Underlying it is a live Tcl interpreter with an extension called "tk" loaded into the interpreter. Most Tkinter commands, methods and objects eventually wind up as invocations of tcl commands. For example, when you do something like:

root = tk.Tk()
f = tk.Frame(root)
b = tk.Button(f, text="Press me!")

...它被翻译成(大致)这样的:

... it gets translated into something (roughly) like this:

package require tk
frame .f
button .f.b -text "Press me!"

(注意:Tkinter 实际上生成比 .f.f.b 更复杂的名字,但概念是一样的)

(note: Tkinter actually generates more complex names than .f and .f.b, but the concept is the same)

call 方法是这个底层 tcl 解释器的接口.它允许您构造一个 tcl 命令并要求解释器运行它.它是python和tcl之间的桥梁.

The call method is the interface to this underlying tcl interpreter. It allows you to construct a tcl command and ask the interpreter to run it. It is a bridge between python and tcl.

它通常不用于应用程序级代码,尽管在 tcl/tk 周围的 Tkinter 包装器不提供对 tcl/tk 支持的某些功能的访问的极少数情况下它可能很有用.

It is not typically used in application-level code, though it can be useful in the rare cases where the Tkinter wrapper around tcl/tk doesn't provide access to some feature supported by tcl/tk.

这篇关于“tk.call"有什么作用?函数在 Python/Tkinter 中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆