Would it be possible to make the vertices of a tree graph clickable, executing a function when clicked?

Specifically, I am using Mathematica / the Wolfram Language to prototype a modern, microtonal synthesizer I call 'PTOLEMUSE'. Its function is to afford a person the ability to hear the sound of epimoric / superparticular ratios in relation to a tonic frequency in hertz. Here's what I have so far:

limitation = 32 ;
relations = List[];
reciprocals = List[];

EpimoricRatios = # / (# - 1) & [ Range[2, limitation] ] ;
ReciprocalRatios = (# - 1) / # & [ Range[2, limitation] ];

For[child = 1, 2 child < Length[EpimoricRatios], child++,
  AppendTo[relations, {EpimoricRatios[[child]] \[UndirectedEdge]
     EpimoricRatios[[2 child]],
    EpimoricRatios[[child]] \[UndirectedEdge]
     EpimoricRatios[[2 child + 1]]}]];

For[child = 1, 2 child < Length[ReciprocalRatios], child++,
  AppendTo[reciprocals, {ReciprocalRatios[[child]] \[UndirectedEdge]
     ReciprocalRatios[[2 child]],
    ReciprocalRatios[[child]] \[UndirectedEdge]
     ReciprocalRatios[[2 child + 1]]}]];

GraphTree[TreeGraph[Flatten[relations], VertexLabels -> "Name"]]
GraphTree[TreeGraph[Flatten[reciprocals], VertexLabels -> "Name"],
 TreeLayout -> Bottom]

This produces the following tree graphs:

Enter image description here

Enter image description here

  • 1
    $\begingroup$ You can apply Button to the nodes. You can do this either when constructing the nodes/edges, or you can use TreeMap on the GraphTrees that you create later. $\endgroup$
    – lericr
    Jul 8, 2022 at 20:43

1 Answer 1


Maybe something like this:

upperGraph = 
  TreeGraph[Map[Button[#, Speak[#]] &, Flatten[relations], {-1}], VertexLabels -> "Name"];
upperTree = GraphTree[upperGraph, ImageSize -> 1000, TreeLayout -> Top]

(Speak is just an example, you'd use whatever your special function is)

  • $\begingroup$ My friend, you TOTALLY ROCK! this is exactly what I needed! $\endgroup$ Jul 8, 2022 at 22:07
  • $\begingroup$ I apparently don't have enough credits to boost the score of your answer, unfortunately. Yet I tried the code, and am very pleased! THANK YOU FOR YOUR HELP! $\endgroup$ Jul 8, 2022 at 22:08
  • $\begingroup$ You're welcome. I should say that what I did was a quick-and-dirty example. You should experiment a bit to come up with something clean and maintainable. $\endgroup$
    – lericr
    Jul 8, 2022 at 22:30

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.