Dear all, I'm trying to use tcltk to build a small user-interface and couter the problem: It seems that sometimes the dialog box will be minimized automatically though I want it to be on top of the screen all the time. For example, when runing the following code, if you type in "a1", "a2", "a3", etc when being asked for an integer, the program is supposed to keeping asking you until you give an integer. The program runs fine, but the dialog box is not always on top, and it is annoying having to maximized it every time (the wierd thing is that sometimes it is Ok, sometimes it is not. So I don't know the problem.) Millions of thanks! Hua ##==============================================## Add Dialog Box (with only "OK" button) ##==============================================modalDialogOK <- function(title,question,entryInit,entryWidth=10) { returnValOnCancel="ID_CANCEL" dlg <- tktoplevel() tkwm.deiconify(dlg) tkgrab.set(dlg) tkfocus(dlg) tkwm.title(dlg,title) textEntryVarTcl <- tclVar(paste(entryInit)) textEntryWidget <- tkentry(dlg,width=paste(entryWidth),textvariable=textEntryVarTcl) tkgrid(tklabel(dlg,text=" ")) tkgrid(tklabel(dlg,text=question),textEntryWidget) tkgrid(tklabel(dlg,text=" ")) ReturnVal <- returnValOnCancel onOK <- function() { ReturnVal <<- tclvalue(textEntryVarTcl) tkgrab.release(dlg) tkdestroy(dlg) # tkfocus(dlg) tkfocus(ttMain) } OK.but <-tkbutton(dlg,text=" OK ",command=onOK) tkgrid(OK.but) tkgrid(tklabel(dlg,text=" ")) tkfocus(dlg) tkbind(dlg, "<Destroy>", function() {tkgrab.release(dlg);tkfocus(ttMain)}) tkbind(textEntryWidget, "<Return>", onOK) tkwait.window(dlg) return(ReturnVal) } ##==============================================## main function ##==============================================require(tcltk) ttMain <- tktoplevel() tkwm.title(ttMain,"Number") tkdestroy(ttMain) #initial values are set numAll = "" speAll = NULL yrunit = "" ttMain <- tktoplevel() tkfocus(ttMain) numAll <- as.numeric(modalDialogOK("Number","Put in an integer greater than 1:",entryInit=numAll)) tkdestroy(ttMain) while (is.na(numAll) || numAll==0 || numAll==1) { ttMain <- tktoplevel() tkfocus(ttMain) ReturnVal <- tkmessageBox(title="Number",message="Error! The number of should be NUMERICAL and be greater than 1!",icon="info",type="ok") tkdestroy(ttMain) ttMain <- tktoplevel() tkfocus(ttMain) numAll <- as.numeric(modalDialogOK("Number","Put in an integer greater than 1:",entryInit=numAll)) tkdestroy(ttMain) } ##==============================================## end of code ##===============================================