7
$\begingroup$

Why won't

EventHandler["text", {"MouseClicked" :> (output = Input[];)}]

work?

When I click "text" the kernel hangs.

$\endgroup$
5
  • 1
    $\begingroup$ can you expand a little more on what you're trying to do? $\endgroup$
    – kale
    Aug 24, 2012 at 15:11
  • $\begingroup$ The real application would be something like, clicking in a graphics object, and saving the coordinates and a label that I input using Input[]... $\endgroup$
    – Peter
    Aug 24, 2012 at 15:13
  • $\begingroup$ Is that code what you've been using? It contains an error: "MouseClicked" > action should be "MouseClicked" -> action. $\endgroup$
    – rcollyer
    Aug 24, 2012 at 15:15
  • $\begingroup$ I use "MouseClicked" :> action, I corrected the error $\endgroup$
    – Peter
    Aug 24, 2012 at 15:26
  • $\begingroup$ Welcome to Mathematica.SE! Let me remind you three things we usually do here: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign` $\endgroup$ Aug 25, 2012 at 8:33

1 Answer 1

10
$\begingroup$

You are facing an issue similar to described here . The problem is Button has option Method -> "Queued" and EventHandler does not have anything similar. Here is a way around it:

DynamicModule[{output = "click to change"}, Button[Dynamic[output], 
  output = InputString["Enter new text", "click to change"], 
  Method -> "Queued", Appearance -> "Frameless"]]

enter image description here

If you just must use EventHandler, then CreateDialog is a work around:

output = "click to change";
EventHandler[ Dynamic[output], {"MouseClicked" :> 
   CreateDialog[{TextCell["Enter new text"], 
     InputField[Dynamic[output], String], 
     DefaultButton[DialogReturn[output]]}]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ I thought scheduled tasks could help here, but they have the same problem. Might be because scheduled tasks don't need a frontend and Input probably runs in the frontend? $\endgroup$ Aug 25, 2012 at 7:08

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.