TclTk 图像宽度总是 returns 零

TclTk image width always returns zero

Linux Debian 杰西

我已经在 TclTk 中创建了照片图像。创建后,我想查询实际宽度,以便我可以使用它。我在 MWE 中使用常量 500 的地方在实际程序中不太明显。

% puts $tcl_version
8.6
% package require Tk
8.6.2
% set i [image create photo p0 -width 500]
p0
% #not correct
% image width p0
0
% #correct
% p0 cget -width
500

来自图像手册页:

image width name

Returns a decimal string giving the width of image name in pixels.

所以我希望

image width p0

也 return 宽度的十进制值。 cget 命令执行 return 我所期望的。

我做错了什么?

尝试:

set i [image create photo p0 -width 500 -height 1]

显然高度无效的图像没有宽度。