I'm wondering if it's possible to set actions to the words in a WordCloud. I'd like to press a word and have it printed. I noticed here that Button[] can be used like ToolTip[] so changed the example code

entities = EntityValue[CountryData[], {"Name", "Population"}];
WordCloud[{Tooltip[#[[1]], #[[2]]], #[[2]]} & /@ entities]

into this but didn't work 'cause strings were expected. Then I thought that maybe an hyperlink would work but this only works with URL, right?

WordCloud[{Button[#[[1]], Print[#[[1]]]]} & /@ entities]

Thank's for your help

  • 3
    $\begingroup$ try WordCloud[{Button[#[[1]], Print[#[[1]]]]} & /@ entities] or WordCloud[{Button[#[[1]], Print@ #], #[[2]]} & /@ entities] $\endgroup$
    – kglr
    Commented Sep 8, 2020 at 4:05
  • $\begingroup$ Thank's, the second option worked $\endgroup$ Commented Sep 8, 2020 at 14:55

1 Answer 1


The elements of the input list should be of the form {Button[$string_i$, $action_i$], $weight_i$} or,for unweighted data, just Button[$string_i$, $action_i$]. So

 WordCloud[{Button[#[[1]], Print@#], #[[2]]} & /@ entities]

works as expected:

enter image description here

You can remove the braces around Button[...] in your code to get an unweighted word cloud:

WordCloud[Button[#[[1]], Print@#] & /@ entities]

enter image description here


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.