python - 从 Tcl 字典获取 Python 字典

标签 python tcl

我想在单个 tk.call 中从 Tcl 字典中获取 python 字典。这有可能吗?

例子:

import tkinter

desiredDict =  {"first": "Foo", "second": "Bar", "third": "Baz"}

tk = tkinter.Tcl()
tk.call("set", "data(first)", "Foo" )
tk.call("set", "data(second)", "Bar" )
tk.call("set", "data(third)", "Baz" )
foo = tk.call("array", "get", "data" )
tclKeys =  tk.call("dict", "keys", foo)
fromTcl  = tk.call("dict", "get", foo, "first")

print(foo)
print(tclKeys)
print(fromTcl)
print(type(foo))
# print(dir(foo))

我知道我可以使用 tk.call("dict", "keys", foo) 获取键,然后使用 tk.call("dict", "get", foo, "...") 但我想在一个 tk.call 中获取 Python 字典(参见 desiredDict)。这不是 gui 问题,我在这里没有使用 gui。

最佳答案

Tkinter 中没有用于检索 Tcl 字典的公共(public)函数,但有一个私有(private)函数:

>>> tkinter._splitdict(tk, foo)
{'second': 'Bar', 'third': 'Baz', 'first': 'Foo'}

关于python - 从 Tcl 字典获取 Python 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55244766/

相关文章:

python - 如何使用Python3在PyCharm中编写多个签名提示

regex - 需要处理 TCL 正则表达式的指导

c - 如何在TCL中运行预编译的C代码?

path - 如何在Unix下使用tcl/TK查找应用程序中加载的所有命名空间的文件路径?

windows - Windows 控制台中的 Tcl 和 Ctrl-C

python - 带有 Python 的 OpenCV 中的 imageData 函数

python - 在 Python 的 matplotlib 中使用时间序列的百分位数设置颜色渐变

python - 为什么 pandas 使用 (&, |) 而不是正常的 pythonic (and, or)?

python - 如何同时支持 argparse 和 optparse?

foreach - 我们可以在 tcl 中使用这样的 foreach 循环吗?