Version 1 of wm aspect

Updated 2002-03-26 20:59:55

A subcommand of Tk's wm command, this allows you to enforce aspect ratios when resizing a window.

Usage:

 wm aspect . <minAspect> <minDenominator> <maxAspect> <maxDenominator>

The window name must always be specified. The aspect ratios must either be all specifed or all omitted. <minAspect>/<minDenominator> forms the minimum allowed aspect ratio, and <maxAspect>/maxDenominator> forms the maximum allowed aspect ratio. Examples:

 wm aspect . 4 3 4 3
 wm aspect . 3 2 5 2
 wm aspect .
 wm aspect . "" "" "" ""

wm aspect . 4 3 4 3 will fix the aspect ratio of the window at 4/3. Because the command requires specification of both min and max aspects, it is necessary to specify the aspect twice. wm aspect . 3 2 5 2 will set the minimum aspect ratio at 3/2, and the maximum at 5/2. When resizing the window, it will be possible to shape it to any aspect ratio that falls between these two ratios.

wm aspect . will return a list of the current aspect settings, or an empty list if there is no aspect ratio currently set.

wm aspect . "" "" "" "" will clear the aspect ratio constraints. Note that since all four numbers must be specified, you actually have to pass the command four empty strings.

Note: This command apparently does not validate its arguments, and it is possible to confuse the window manager somewhat (or severely) if you specify contradictory ratios, or if you specify a smaller max aspect than min aspect.

(Can anyone suggest any practical use for this capability?)

How about an image viewer, where the image dimensions are known, but the user may want to scale the window size?

(If anyone in charge of this is paying attention here, how about making it possible to clear the aspect ratio constraints by setting them to zero?)

People are more likely to pay attention if this query is logged at SourceForge as a feature request.

-EE


Tk syntax help - Category Command