Prevent [Ruby/]Tk window resizing


Screenshot showing a tk window that can't be resized

I had some trouble finding how to prevent Tk windows from being resized by users at runtime, so now that I've found out how I'm putting it here and passing it off as a legitimate post. Clever, right? :). Entirely pointless introductory paragraphs aside, simply set the resizable attribute of the TkRoot to (0, 0). Looks like a guy with a crooked nose.

For example, if you're a Rubyist using a beautiful block to create your new TkRoot window:

rootMain = |main| do
  resizable 0, 0

Or if you're doing it the more traditional way with hash parameters:

rootMain ={ 'resizable' => '0, 0', [..] }

And because I used to be a Perl Guy and still use it for some stuff:

$rootMain->resizable(0, 0);

The next thing I need to find out is how to allow only horizontal resizing while vertical resizing is locked, and vica versa. Any ideas?

Author bio and support


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.