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?


1 Answer 1

img = Nothing;
   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.

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

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.