0
$\begingroup$

I am trying to create a graphics that outputs the population of a city on the graphics that is clicked. The problem is that it is not updating the last point that is clicked. Please help.

Button[Graphics[{Gray, CountryData["Australia", "Polygon"],
   PointSize[Large], Red,
   Tooltip[Point[Reverse[
        CityData[#, "Coordinates"]]], me = CityData[#, "Name"]] & /@ 
    CityData[{Large, "Australia"}]}], 
 Print[CityData[me, "Population"]]]
$\endgroup$
2
$\begingroup$

Wrap the assigment me = CityData[#, "Name"] in Dynamic, so that instead of being evaluated only when the button is created, it is evaluated each time the Tooltip is activated:

Button[Graphics[{Gray, CountryData["Australia", "Polygon"], 
   PointSize[Large], Red, 
   Tooltip[Point[Reverse[CityData[#, "Coordinates"]]], 
      Dynamic[me = CityData[#, "Name"]]] & /@ 
    CityData[{Large, "Australia"}]}], 
 Print[CityData[me, "Population"]]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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