When and how to set window size using Tk
<p>I'm writing a script to output things to a window comprising a Tkhtml widget and a text widget displayed above each other in a ttk::panedwindow. Both widgets are scrollable both vertically and horizontally. There's also a button allowing the user to clear the text widget.</p>

<p>I'm doing some of the development on a laptop running Ubuntu. The window manager allows for four desktop workspaces in a 2x2 array, and when the GUI is first displayed, the bottom fifth or so bleeds from the workspace I'm using into the one below. It's irritating to have to muck around resizing the window to make it short enough to fit onto the screen so I want to resize it.</p>

<p>(I think) I know approximately how to do this, i.e bind to an appropriate event so that I can run a script when the window is first displayed. (Reset the binding from within the script so that it only fires once.) I believed that the "appropriate event" was <code>&lt;Map&gt;</code>, but when the window was first mapped, the two widgets had zero height (as reported by <code>[winfo height]</code>). I tried binding to <code>&lt;Expose&gt;</code> and this seems to work, (<code>[winfo height]</code> returns sensible numbers,) so:</p>

<h1>Question 1: Which event should I bind to?</h1>

<p>When the binding fires, <code>[wm geometry]</code> reports the geometry as 815x1029+49+24, <code>[winfo height]</code> reports the two heights of the two widgets as 600 and 366, and <code>[wm screenheight]</code> returns a height of 800. I know there are various other bits and pieces in the GUI so I'm not surprised that there are 63 pixels unaccounted for in the initial layout. I assume that I need the same amount of space after resizing, so I should request a geometry of 815x737+49+24, but when I do, a sliver (approximately the lower horizontal scrollbar) still bleeds onto the next workspace.</p>

<p>By mucking around manually, I know that when everything fits nicely onto the screen the geometry should be 815x717+49+24, so I've added a fudge factor of 20 to the amount of space I allow for the "other bits and pieces of the GUI". This works fine but seems a little inelegant (massive British understatement :-) ), so:</p>

<h1>Question 2: What have I missed, requiring use of a fudge factor?</h1>

<p>I'm using Tk 8.6.1 on Ubuntu 12.04.5 LTS. I'm using version 0.9.7.12 of the Compiz window manager.</p>

<h1>Update</h1>

<p>It struck me that I ought to find the height of the various panes, rather than the Tkhtml and text widgets as that would account for the scrollbars and the "Clear" button. The pane heights are 615 and 409 initially, but this just means that I have to increase my fudge factor from 20 to 78 to get the request height to my desired value of 717. Is there any way to predict what height to request for the toplevel containing my paned window in order to get that toplevel to fill the screen?</p>