简体   繁体   English

如何在R / tcltk中将顶级窗口居中

[英]How to center a toplevel window in R / tcltk

I'm new to R and tcltk. 我是R和tcltk的新手。 I use tcltk to create a window. 我使用tcltk创建一个窗口。

Every time I call tktoplevel() , the new window appear at top left of the screen, and I have to move it myself every time. 每次调用tktoplevel() ,新窗口都会出现在屏幕的左上方,而我每次都必须自己移动它。 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) ? 有一些命令可以执行tktoplevel(centre=T)吗? put the new toplevel widget in the middle of the screen. 将新的顶级小部件放在屏幕中间。

Tk has an undocumented built-in command for doing this. Tk具有未记录的内置命令来执行此操作。 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. 一些布局可能需要在幕后运行非平凡的约束求解器才能正确运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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