TkText resizing

require 'tk’
root = TkRoot.new()
question = TkText.new(root).pack(‘fill’=>‘both’, ‘expand’=>true)
stats = TkLabel.new(root) { text ‘blah’; }.pack(‘anchor’=>‘w’)
answer = TkEntry.new(root).pack(‘fill’=>‘x’)
Tk.mainloop

The window elements seem to expand just fine, but when I shrink the
window back down, the TkText refuses to decrease its size at some
point. It is as if it thinks it must be a minimum of 10 lines or so.
TIA.

Hi,

···

From: bsl04@comp.uark.edu (Brian)
Subject: TkText resizing
Date: Thu, 13 Feb 2003 16:47:55 +0900
Message-ID: ddf1b30b.0302122331.361b2d99@posting.google.com

The window elements seem to expand just fine, but when I shrink the
window back down, the TkText refuses to decrease its size at some
point. It is as if it thinks it must be a minimum of 10 lines or so.

The size restricted by the ‘height’ option of the text widget.
You can remove the restriction by setting the ‘height’ option to 1.
However, you get 1 line of text widget on initial window.
To avoid this, you need a trick to control ‘pack’ geometry manager.
Please see the following script.

require ‘tk’
root = TkRoot.new()
question = TkText.new(root).pack(‘fill’=>‘both’, ‘expand’=>true)
stats = TkLabel.new(root) { text ‘blah’; }.pack(‘anchor’=>‘w’)
answer = TkEntry.new(root).pack(‘fill’=>‘x’)
Tk.update #==> (A)
root.pack_propagate(0) #==> (B)
question.height(1) #==> (C)
Tk.mainloop

It has additional 3 lines for your original script.
The most important line is line (B).
This prohibits propagation of size of slave widgets to root widget.
So, even if set height of the text widget to 1 on line (C),
size of root widget is not changed. And, depend on ‘fill’ option
on packing, the text widget keeps its size.
The reason of why line (B) has not to evaluate before packing the
text widget is to set the size of the text widget to default size.
If execute line (B) before packing slave widgets,
the window size is decided by default size of root widget.
Therefore, after fixing the window size by packing all slave widgets
and updating all widgets by line (A), line (B) must be execute.

There is a bug on pack_propagate method.

So, fail to set the propagate mode to false by

root.pack_propagate(false).


Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

To avoid this, you need a trick to control ‘pack’ geometry manager.

That was perfect! Thank you.
brian.