bk888
bk888

Reputation: 11

Is there a way to set tcl/tk canvas minsize?

I have a pop-up, which is a canvas, for which I wish to allow the user to drag it out to any size they wish, however it can collapse to something very small and unusable. Is there a way to set a canvas minsize? (e.g. like "wm minsize") Hopefully the answer is not to embed the canvas "in a window".

Upvotes: 1

Views: 595

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137587

The natural minimum size for a canvas is 1×1.

Typically, the actual minimum size for a canvas is set up by the geometry manager; since most of the time you want to use a grid for containing a canvas (so you can arrange scrollbars right) setting the minimum sizes for the relevant row and column are the key thing:

set master .
set canvas .canv

# Go for a minimum size of 400x200
grid columnconfigure $master $canvas -minsize 400
grid rowconfigure    $master $canvas -minsize 200

The pack GM doesn't allow you to specify the minimum size at all; it uses a layout model that doesn't have that concept. The place lets you say everything directly, but doesn't really help in most situations. If you're embedding the canvas in another widget (e.g., in a text widget) there might be other options.

Note that you can't actually force the system to obey the minimum size directives you give. They're just (really strong) hints. (You might want to also look into the wm minsize command to control the requested sizing of the overall toplevel window, but that's independent; the minimum sizing of the widget isn't the minimum sizing of the overall container, though they can interact.)

Upvotes: 2

Related Questions