Tcl/Tk: Maximize window / determine if window is maximized?

元气小坏坏 提交于 2019-12-11 05:41:52

问题


Can I find out if my toplevel window is maximized, and can I maximize it programmatically? I am using R's tcltk package 8.5 on Windows XP.

The reason for the question is: I want to enforce a <Visibility> event by calling first withdraw and then deiconify. However, if the window was maximized before these two function calls, it is not after these calls. Is there an easier way to enforce the event?


回答1:


You can discover the whether the window is maximized with wm state $toplevel (look for zoomed as a return value). But…

The OS doesn't generate <Visibility> events properly for you on Windows; you only get them on the window being mapped, and that's subtly different. (Windows tells you much less about the stacking order and its consequences than X does; Tk's pretty close to X's model.) You don't say why you want this event though; perhaps there's something else that will serve your real purpose?




回答2:


Wrote a function that propagates the Visibility event to a given widget and all its children.

tkevent.propagate <- function(w,e) {
  tkevent.generate(w, e)
  children <- as.character(tkwinfo("children", w))
  if(length(children)>0) lapply(children, function(c) tkevent.propagate(c,e))
}

This way, I don't need to call withdraw/deiconify and get my event to each widget.



来源:https://stackoverflow.com/questions/3428368/tcl-tk-maximize-window-determine-if-window-is-maximized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!