0

I would like to scale an image according to the size of a frame that is not the toplevel, for that I'm trying to get the geometry of said frame and re-plot the image according to the results that will be returned. At the moment I'm trying only to get the geometry like the code bellow:

require(tcltk) || stop("tcltk support is absent")

# Main Window
base <- tktoplevel(padx=20, pady=20)
# Change title using tk window manager
tkwm.title(base,'Test App')
# Main Window Frame
main_frame <- tkframe(base)

tools_frame <- tkframe(main_frame)
label <- "Tools Frame"
lab_tools <- tklabel(tools_frame,text=label,width=80)
tkpack(tools_frame,lab_tools)

body_frame <- tkframe(main_frame)

bd_left_frame <- tkframe(body_frame, padx=5, pady=5)

bd_left_label <- tklabel(bd_left_frame, text='Left Body Frame')
tkpack(bd_left_frame, bd_left_label)
tkpack(body_frame, bd_left_frame, side='left', anchor='n', expand=1, fill='both')

bd_right_frame <- tkframe(body_frame, padx=5, pady=5)

bd_right_frame_a <- tkframe(bd_right_frame)

bd_right_label_a <- tklabel(bd_right_frame_a, text='Right Frame A')
tkpack(bd_right_frame_a, bd_right_label_a)
tkpack(bd_right_frame, bd_right_frame_a)

bd_right_frame_b <- tkframe(bd_right_frame)

bd_right_label_b <- tklabel(bd_right_frame_b, text='Right Frame B')
tkpack(bd_right_frame_b, bd_right_label_b)
tkpack(bd_right_frame, bd_right_frame_b)

tkpack(body_frame, bd_right_frame, side='right', anchor='n', expand=1, fill='both')

tkpack(main_frame, tools_frame)
tkpack(main_frame, body_frame)

# CALLBACKS
onResize <- function() {
  geo <- tkwm.geometry(bd_right_frame_b)
  print(geo)
}

# Window Event Binds
tkbind(base, '<Configure>', onResize)

tkwait.window(main_frame)

The thing is, it won't work with non top level frames, how could I do this instead?

Matheus Fernando
  • 159
  • 3
  • 11
  • I wrote some `tcltk`-based data exploration tools at a job years ago (twenty, give or take) and if memory serves these 'geometry' aspects are window manager specific. You may not get that from `tcltk`. I recall having started with an _imposed_ size of, say, 800x600. – Dirk Eddelbuettel May 22 '23 at 13:29
  • normally you can deal with that with `winfo reqheight` and `winfo reqwidth` [see this link](https://www.tcl.tk/man/tcl/TkCmd/winfo.html#M28) and you also can get *true values* by `update idletasks` but don't know how you write it in R-language. – Thingamabobs May 22 '23 at 14:55

0 Answers0