简体   繁体   中英

How to center a toplevel window in R / tcltk

I'm new to R and tcltk. I use tcltk to create a window.

Every time I call tktoplevel() , the new window appear at top left of the screen, and I have to move it myself every time. I know how to position things in those windows, by I don't know how to position the windows on the screen.

Are there some commands that can do tktoplevel(centre=T) ? put the new toplevel widget in the middle of the screen.

Tk has an undocumented built-in command for doing this. You just need to tell it the name of the window to centre and it will do the rest.

.Tcl.objv("tk::PlaceWindow", thetoplevelwindow)

Make sure you've filled out the contents of the toplevel before you call this; the command needs to be able to compute the size of the content to work out how to place the window. It also runs the event loop, because that's required to get all the size information to propagate; some layouts may require running a non-trivial constraint solver behind the scenes to get right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM