There is something wrong with the way I assemble my Tk windows (with R tcltk and tcltk2, under Win XP)
library(tcltk)
library(tcltk2)
expandTk <- function() {
root <- tktoplevel()
# textbox with scroll bars
textbox <- tk2frame(root)
scr <- tkscrollbar(textbox, repeatinterval=5, command=function(...) tkyview(txt,...))
txt <- tktext(textbox, bg="white", font="courier", wrap="word", yscrollcommand=function(...)tkset(scr,...))
tkpack(txt, side="left", fill="both", expand=TRUE)
tkpack(scr, side="right", fill="y")
tkmark.set(txt,"insert","0.0")
tkpack(textbox, fill="both", expand=TRUE)
# status bar and size grip
statusText <- tclVar("")
f <- tk2frame(root, relief="sunken")
l <- tk2label(f, textvariable=statusText)
tkpack(l, side="left", pady=2, padx=5, expand=0, fill="x")
tkpack(f, side="left", expand=1, fill="x", anchor="s")
sg <- ttksizegrip(root)
tkpack(sg, side="left", expand=0, anchor="se")
}
The window looks fine, but as soon as I resize it (ie make it smaller), the scrollbar and the statusbar disappears. I am quite sure that this is a user error, I have seen other Tk apps which resize properly, but I can not figure out which option I should use…
Any hint appreciated,
Karsten
That’s standard behavior for the Tk
packgeometry manager. Here’s a relevant section of thepackman page:So if you shrink the overall window to be smaller than the space requested for the text widget, you leave no space for the other widgets, and they get unmapped.
The best solution is to use the
gridgeometry manager, instead ofpack. Generally speaking, I findgridto be much easier to use and capable thanpackanyway, although your mileage may vary. In particular, it eliminates the need for many superfluous frame widgets, which can simplify your code a lot.I think you can use something like this:
There’s some more information about using the
gridgeometry manager from R here.