Can I insert a button in an image at specified location? I have tried but it shows Button is not a graphic function.


3 Answers 3


Lets get an image:

img = ExampleData[{"TestImage", "Lena"}];

Overlay is pretty easy to use for location specification. In the case below I used scaled coordinates:

Overlay[{img, Button[Style["Image Histogram", Blue, Italic, 34], 
   CreateDialog[ImageHistogram[img]]]}, All, 2, Alignment -> {.7, -.8}]

enter image description here

Here is a simple line to understand better how to place the button in different locations:

Overlay[{img, Button[Style["Image Histogram", Blue, Italic, 8], 
     CreateDialog[ImageHistogram[img]]]}, All, 2, Alignment -> #] & /@Tuples[{.7,-.7}, 2]

enter image description here


You can use an inset:

   RandomImage[CauchyDistribution[0, .2], {100, 100}, 
    ColorSpace -> "RGB"], Center], 
  Inset[Button["Click Here", Print[10!]], {Center, -0.5}]}, 
 Frame -> True]

or maybe you don't want to put it on the image, but somewhere near it use this :

{Button["Transform", CreateDialog[ImageHistogram[img]]], Show[

Which works exactly the same but looks a little different.


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.