开发者

Perl TK resize window

Is it possible to automatically resize a Tk window to开发者_高级运维 the width and height of the text inside of the text plot?


You can easily measure how wide some text is in a particular font:

$font = $widget->Font(....);              # Get the font however you want
$lineWidth = $font->measure($text);       # Do this for each line; take the max
$lineHeight = $font->metrics(-linespace); # Get the height of a line; x # lines

Add in a bit of slop for borders, etc., and use this to set the size of the toplevel:

$toplevel->configure(-width=>$width, -height=>$height);

If it's not a toplevel that you want to control, it's easiest to do this by putting the contents in a frame and controlling the size of that frame (same method, same options). Also be aware that if you have too many rows or too long lines, it won't fit on the screen anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜