简体   繁体   中英

R close `menu` window (tcltk)? (equivalent to graphics.off for tcltk?)

Quick question - I'm using the menu function in R with graphics=TRUE . For me, as I'm on linux, this results in a tcltk dialogue being shown. (You know how when you do install.packages('some_package') R pops up a window telling you to select which CRAN mirror you wish to remove? That's what I mean).

Sometimes after I make my selection (which works fine), the window then refuses to disappear or respond to any sort of clicks - I can continue my R session as normal but this window will hang around and despite my efforts to shut it down (via the close 'x' button in the corner, or via the 'OK' and 'Cancel' buttons on the dialogue itself).

Is there a way I can destroy this window, given that I don't have a handle to it? I'm looking for an equivalent of graphics.off for tcltk.

Additionally, I've noted that I often get an error [tcl] grab failed: window not viewable. when using menu(..,graphics=TRUE) , so this could be related.

cheers.

Stuff that only happens sometimes is hard to reproduce, and is often due to bugs, and hard to figure out without a complete spec of your machine. However, I can reliably get similar behaviour and I can fix it:

> library(tcltk)
Loading Tcl/Tk interface ... done
> menu(letters[1:5],graphics=TRUE)
^C

By hitting Control-C at this point I get my R prompt back and an unresponsive dialog box, which I don't have a handle on. Using the window manager controls on it do nothing, resizing it doesn't update the window. So...

> tclServiceMode(TRUE)
[1] FALSE

then it wakes up. Then I can either close the dialog conventionally,or do:

> tkdestroy(".1")
Error: $ operator is invalid for atomic vectors

which gets rid of it with an error I don't understand. The ".1" is the window path, which is the same as the default window title - but not if you've set a name on your menu. In which case... Ummm there's probably a way to look it up from the name, but anyway, once you've set the service mode to TRUE you can click your way back to desktop tidyness.

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