Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem using MousePosition. I want to restrict the value returned by MousePosition to a specific Graphics object. Consider the following example:

g1 = Graphics[{Green, Disk[]}]; 
g2 = Graphics[{Blue,Disk[]}];
{g1, g2, Dynamic[MousePosition["Graphics"]]}

I would like to have the mouse position updated only if the mouse is on the second (blue) disk and not on the first one (green). This seems to be an easy problem, but I can't figure out how it works in Mathematica.

Thanks for help!

share|improve this question
up vote 5 down vote accepted

Something like this?

g1 = Graphics[{Green, Disk[]}];
g2 = Graphics[{Blue, Disk[]}];
{g1, Mouseover[g2, Dynamic@(mp = MousePosition["Graphics"]; g2)], Dynamic@mp}

Mathematica graphics

share|improve this answer
Thanks, that helped for me. – g3kk0 Jul 19 '13 at 17:50

I have overlooked the example in the help for MousePosition

Graphics[Disk[Dynamic[MousePosition[{"Graphics", Graphics}, {0, 0}]]],
  PlotRange -> 10, ImageSize -> 100]

With that the value returned by MousePosition is restricted to the Graphics object it is associated with.

share|improve this answer

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.