When you create a Tk Text widget you can specify its size as -height
and -width
measured in lines and characters in the default font.
If the widget later gets resized, I want to read the new size in lines and chars, but I can't see how. I'm not changing the font at all. Binding to the <Configure>
event will report the new size in pixels in %h and %w. Doing cget -height
or cget -width
just reports the originally configured line and char sizes. Is there a way to detect the new size in lines and characters?
You can take the width in pixels and make an estimate:
set width [expr {round($pwidth/[font measure TkTextFont 0])}]
Height would be something like:
set height [expr {round($pheight/[font metrics TkTextFont -linespace])}]
Substitute TkTextFont
with the actual font that is used.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments