Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

PopupWindow objects can be clicked multiple times, opening multiple popup windows for the same object. How can I prevent this?

A bit more detail: I have an application which displays a graphic. The user can click on elements of the graphic to call up an information panel about that element using PopupWindow. The user might have several of these popups open at once. To prevent confusion, I would like to make sure that the user cannot open more than one popup per object. I can't see a straightforward approach to doing this, so I'm hoping for some ideas from this fine community.

Example code:

DynamicModule[{col = ConstantArray[Blue, 5]},
 Graphics[{Table[With[{i = i},
       col[[i]] = If[CurrentValue["MouseOver"], Red, Blue];
       {Dynamic@col[[i]], Disk[{i, 0}, 0.5]}],
       col[[i]] = If[CurrentValue["MouseOver"], Red, Blue];
       Framed[Style["Disk " <> ToString[i], White, 20], 
        FrameMargins -> 80, Background -> Dynamic@col[[i]]]], 
      WindowSize -> 280]
     ], {i, 5}]}]]

Here I have clicked on disk 4 twice, opening a duplicate of the information window. I want to prevent that:

enter image description here

share|improve this question
Only idea I have is: You could give each PopupWindow title and then check every Notebooks[] every second or so to close duplicates? – Ajasja Oct 30 '12 at 11:57
You can define an index list for windows e.g. from 1 to 5. Before opening a window check if the index is still there in the list then remove the index and open the window else do nothing. – s.s.o Oct 30 '12 at 13:11
I don't think you can do that with PopoupWindow[], because once issued it will ever bring up a window with the specified contents. You can, however, create a notebook if it hasn't been created yet. You may use FE`Evaluate[FEPrivate`GetPopupList["MenuListWindows"]] to check the currently active notebooks. – belisarius has settled Oct 30 '12 at 13:20
@belisarius, thanks. I'm not clear on what your code snippet gives that Notebooks[] doesn't? – Simon Woods Oct 30 '12 at 21:01
@YvesKlett, yes that's normal. You can change the behaviour with WindowFloating->False. – Simon Woods Oct 31 '12 at 8:58

1 Answer 1

up vote 9 down vote accepted

The PopupWindow object is nothing more than a Button with a CreateDocument action:

PopupWindow[a, b] // InputForm

(* Button[a, CreateDocument[Internal`PopupWindowNotebook[b]], 
Appearance -> None, BaseStyle -> {}, DefaultBaseStyle -> {}] *)

Since CreateDocument returns a notebook object which can be assigned to a symbol, it is simple to check if there is an already open popup window. By inserting this check into the Button code, the desired behaviour is obtained:

singlePopup[pw_] := With[{p = Unique["popup"]},
  pw /. Button[a_, b_, c___] :>
    Button[a, If[! ValueQ[p] || Options[p] == $Failed, p = b], c]]

(* e.g. *) PopupWindow["Click here", "You clicked!"] // singlePopup
share|improve this answer
Very nice, a big +1 – belisarius has settled Oct 30 '12 at 23:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.