0
$\begingroup$

I would like a "button" which I could "click on" that would on first click insert a specific photo from a windows file and then, on second click, remove the photo. It could also be two buttons. Or some other scheme. Any thoughts?

$\endgroup$
2
$\begingroup$
img = Nothing;
Button["Click",
 If[
   ImageQ@img,
   img = Nothing,
   f = SystemDialogInput["FileOpen"];
   img = Import[f]];
 ,
 Method -> "Queued"]
Dynamic[If[ImageQ@img, img]]

This button will check if img is an image, if not it will call the file dialog, import the selected file, and display it - you could change f to a fixed filepath if you don't want the dialog. The Method parameter is set to "Queued" to allow the dialog. If img is an image it will reinitialize img to Nothing.

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ Also you may want to use SystemDialogInput["FileOpen", {"Data", {"Data" -> {"*.png","*.jpg", "*.jpeg"}}}] to limit the file picker to images. $\endgroup$ – flinty May 26 at 17:08
  • $\begingroup$ Thank you very much. I will try it. $\endgroup$ – Peter Zug May 26 at 18:36

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.