wm aspect

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

wm aspect window ?minNumer minDenom maxNumer maxDenom?

If minNumer, minDenom, maxNumer, and maxDenom are all specified, then they will be passed to the window manager and the window manager should use them to enforce a range of acceptable aspect ratios for window. The aspect ratio of window (width/length) will be constrained to lie between minNumer/minDenom and maxNumer/maxDenom. If minNumer etc. are all specified as empty strings, then any existing aspect ratio restrictions are removed. If minNumer etc. are specified, then the command returns an empty string. Otherwise, it returns a Tcl list containing four elements, which are the current values of minNumer, minDenom, maxNumer, and maxDenom (if no aspect restrictions are in effect, then an empty string is returned).

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