This is a simplification of a problem that has arisen in a project regarding Euclidean activities for verifying proportions via operations on pairs of magnitudes. In the project, the LocatorPane is used to enter values for x, y that will be used in carrying out operations on pairs of line segments in order to allow the user to ascertain whether the line segments reflect the ratio, y:x, where x, y are positive integers.

The code below captures the essence of the technical problem I have run into.

I am using LocatorPane to select values (x,y) that will be used in each of the tabs in TabView. However, each time a new locator value is selected, the TabView defaults to the first tab, 1. To test this, click on either tab 2 or tab 3; then set the locator value. TabView will automatically reset to tab 1.

Test Code

     1 -> Row[{pt[[1]], pt[[2]]}, "\t"],
     2 -> Row[{2*pt[[1]], 2*pt[[2]]}, "\t"],
     3 -> Row[{3*pt[[1]], 3*pt[[2]],}, "\t"]}],
   LocatorPane[Dynamic@pt, Graphics[{Gray, Disk[]}]]}]]

enter image description here

I tried a variation in which a LocatorPane is placed within each tab, but the reset problem continues to occur.

  • $\begingroup$ related? How to use Locators on a graphic in a tabview $\endgroup$
    – kglr
    Commented Jun 23, 2020 at 22:46
  • $\begingroup$ @kglr. Nice example, from which I can learn. I'm wondering why you didn't have to use Dynamic before TabView, as Michael E2 suggested. $\endgroup$
    – DavidC
    Commented Jun 23, 2020 at 23:57
  • $\begingroup$ DavidC, added Dynamic after an eight year delay:) $\endgroup$
    – kglr
    Commented Jun 24, 2020 at 0:41

1 Answer 1


Add some Dynamic[] and a variable to keep track of the selected tab:

      1 -> Pane[Row[{pt[[1]], pt[[2]]}, "\t"], 150],
      2 -> Pane[Row[{2*pt[[1]], 2*pt[[2]]}, "\t"], 150],
      3 -> Pane[Row[{3*pt[[1]], 3*pt[[2]]}, "\t"], 150]
      }, Dynamic@i], 
   LocatorPane[Dynamic@pt, Graphics[{Gray, Disk[]}]]}], {{pt, {0., 
    0.}}, None}, {{i, 1}, None}]

Oh, I added a Pane because it was a pain with the graphics jumping around depending on how many digits were displayed.

The Dynamic@TabView[...] keeps the whole body of the Manipulate from being re-executed when pt is changed (which interrupts dragging the Locator).

  • $\begingroup$ Very nice. However, I am puzzled as to how Mathematica knows that i stands for the current tab. $\endgroup$
    – DavidC
    Commented Jun 23, 2020 at 23:14
  • $\begingroup$ @DavidC From the second argument Dynamic@i. See the first bullet point under "Details" in the docs for TabView; there are examples under "Scope" as well. $\endgroup$
    – Michael E2
    Commented Jun 23, 2020 at 23:41
  • $\begingroup$ @DavidC I was a little lazy with my explanation: The re-execution (if no Dynamic) does not reset i to 1, so the tab view is preserved; rather, it interrupts dragging the Locator, so it is still necessary. I was misremembering one my trial runs. $\endgroup$
    – Michael E2
    Commented Jun 24, 2020 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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