简体   繁体   中英

TclTk image width always returns zero

Linux Debian Jessie

I have created a photo image in 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.

% 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM