sg_calculator_tkinter_fonts_layout.py

sg_calculator_tkinter_fonts_layout.py uses multiple frames, which fixes the scrollbar problem. It wasn’t clear to me whether I had a scrollbar problem (not binding properly with the text box) or a layout problem (caused by having the scrollbar span 4 rows, which changed with font size). Probably both.

I found a solution by making two frames, placing all the column 0 widgets (six Buttons, two Labels and a Text box) in one frame and the remaining widgets into a second frame.  Then changes to the button font size do not affect the scrollbar. The code for the second frame starts at line 33.  To move the two Labels, two Text widgets and Scrollbar into this frame I changed the widget definitions starting at line 159. If you run the program you won’t see any difference compared to the previous version until you increase the font size.  So on line 124 change my font to helv16b and run the program again.  Now the Scrollbar does not extend past the Text box.

Note that the widgets in the 2nd frame do shift down a bit.  This is because the default alignment is to center the smaller frame.  You can move the contents of the app2 frame up or down by adding a ‘sticky’ option to their configuration.  I have two examples of this, line 39 (sticky = ‘S’, which pins the widgets even with the bottom of the first frame) and line 40, which pins these widgets to the top if you uncomment it.  You can also insert x or y padding if you want the widgets to pin near the top (or bottom) but with an offset.

OK, the key takeaway from this code is that you have more layout flexibility if you put widgets into multiple frames.  And you can move the frames around within the master window (‘root’ in this example) with options like ‘sticky’.