0

I was wondering if it is possible to get a list of windows in Tk, and destroy specific ones. I am working in R using the tcltk interface, and am calling a function written by someone else a long time ago (that I cannot edit) which is producing additional windows that I don't want.

From the documentation here, it seems that new Toplevel windows are children of .TkRoot by default. I know that Python has a winfo_children method, which I was thinking of trying to call on .TkRoot but I don't think that method is implemented in the tcltk library. I tried using tcl("winfo", "children", .TkRoot) but I am getting an error: [tcl] bad window path name "{}" (I'm not familiar with actual tcl, so I'm probably messing this command up).

Additionally, if there is a way to call winfo children, what's the best way to process the result to identify specific windows and then destroy them?

1 Answers1

0

Looking at the R sources, I see that you should be doing:

tkwinfo("children", .TkRoot)

Except that I think that won't work either, as .TkRoot doesn't have a corresponding widget on the Tk side of things. Instead, use the string consisting of a single period (.) as the root of the search; that's the name for the initial window on the Tcl side of things. And I suspect that you'll just get back a raw Tcl list of basic Tk widget names without the R wrapping as I just can't see where that conversion is applied…


Be aware that the results may include widgets that you don't expect, and that you need to call it on every window recursively if you want to find everything.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
  • Thanks! As a side question, is there a reason that they didn't include it in the docs (or did I just not see it)? Is it just because, as they say in the comments above the docs "it's rarely used"? –  Jul 17 '18 at 14:54
  • Ah, I did find it, but it's grayed out for some reason. –  Jul 17 '18 at 14:55