1
$\begingroup$

I have an application where tooltips are used to give information on each of a graphical array of objects. I subsequently want to use the content of the tooltip to create any particular object of interest. If the contents of the tooltip can be written to the paste buffer then I should be able to do this easily. But I haven't been able to figure out how to do this...

$\endgroup$
2
  • $\begingroup$ I'm not sure Mathematica is the best tool for this. Depending on your operation system & the application you are using, there is probably a more direct way to extract the contents of a displayed tooltip, see e.g. this discussion (unless of course your "application" is a Mathematica notebook) $\endgroup$
    – Lukas Lang
    May 4, 2021 at 13:38
  • $\begingroup$ Thanks for that, but my application is indeed a Mathematica notebook! $\endgroup$ May 4, 2021 at 15:00

1 Answer 1

3
$\begingroup$

Since you don't provide the code for your application, let's use this as example:

SeedRandom@1
Graphics[
 {
  AbsolutePointSize@10,
  Tooltip[Point@#, #] & /@ RandomReal[{0, 1}, {10, 2}]
  }
 ]

enter image description here

If we now want to be able to copy something to the clipboard, we can use EventHandler and CopyToClipboard

SeedRandom@1
Graphics[
 {
  AbsolutePointSize@10,
  EventHandler[
     Tooltip[Point@#, #],
     {"MouseClicked" :> CopyToClipboard@#}
     ] & /@ RandomReal[{0, 1}, {10, 2}]
  }
 ]

Now, clicking on a point puts its coordinates into the clipboard. Note that it doesn't need to be a Graphics expression, EventHandler can be used anywhere where Tooltip works.

$\endgroup$
2
  • $\begingroup$ Thanks very much for that - that looks very promising. It will take me a little while to apply it to my application. Unfortunately, my application does not lend itself to giving a brief example - I will see if I can think of something similar to illustrate it. $\endgroup$ May 5, 2021 at 11:21
  • $\begingroup$ This works very well and is simple and versatile. Thank-you very much. One disappointment, which is down to Mathematica, not your Answer, is that Paste[] does not work as expected, so if you write x=Paste[], x is set to Null. This has been noted elsewhere here and here. $\endgroup$ May 6, 2021 at 11:28

Your Answer

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

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