tkInter constraining the width only

A

akineko

Hello everyone,

I'm writing a Tkinter program and trying to constraint the window
size.
I want to set the minimum of the width and the height and the maximum
of the width, but not the height.
I can use minsize(width=min_width, height=min_height) from Wm method
to limit the minimum sizes.
Similarly I thought I could use maxsize(width=max_width, height=None)
to limit the maximum sizes.

Unfortunately, it didn't work.
maxsize() complained if only width is given.

Is there any easy way to constraint a Tkinter window so that the sizes
are set except it can grow vertically.

Any suggestions are greatly appreciated.

Best regards,
Aki Niimura
 
R

Roger

Hello everyone,

I'm writing a Tkinter program and trying to constraint the window
size.
I want to set the minimum of the width and the height and the maximum
of the width, but not the height.

You want to set the max height to 0. I know this is counter-
intuitive. Both values must be a number or None, not mixed. So to do
what you want to do it would be this:

some_window.wm_minsize(width=min_width, height=min_height)
some_window.wm_maxsize(width=max_width, height=0)

Note that these numbers are in pixels if you're using .pack() and
according to the docs it's in grid coordinates if you're using .grid()

Good luck!
Roger.
 
A

akineko

Hello Roger,

Thank you for your prompt response to my posting.
Yes, it worked.
I never thought of putting 0!
A special trick not mentioned in the documentation.

Thanks!
Aki-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top