[英]TclTk image width always returns zero
Linux Debian Jessie Linux Debian 杰西
I have created a photo image in TclTk.我在 TclTk 中创建了一张照片图像。 Once created I want to query the the actual width so I can use it.创建后,我想查询实际宽度,以便我可以使用它。 Where I use the constant 500 in the MWE it is less obvious in the actual program.我在 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
From the image manual page:从图像手册页:
image width name图像宽度名称
Returns a decimal string giving the width of image name in pixels.返回一个十进制字符串,以像素为单位给出图像名称的宽度。
So I would expect所以我希望
image width p0
to also return the decimal value for the width.还返回宽度的十进制值。 The cget
command does return what I expect. cget
命令确实返回了我所期望的。
What am I doing wrong?我究竟做错了什么?
Try:尝试:
set i [image create photo p0 -width 500 -height 1]
Apparently an image with an invalid height does not have a width.显然,高度无效的图像没有宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.