Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Why won't

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

work?

When I click "text" the kernel hangs.

share|improve this question
1  
can you expand a little more on what you're trying to do? –  kale Aug 24 '12 at 15:11
    
The real application would be something like, clicking in a graphics object, and saving the coordinates and a label that I input using Input[]... –  Peter Aug 24 '12 at 15:13
    
Is that code what you've been using? It contains an error: "MouseClicked" > action should be "MouseClicked" -> action. –  rcollyer Aug 24 '12 at 15:15
    
I use "MouseClicked" :> action, I corrected the error –  Peter Aug 24 '12 at 15:26
    
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` –  Vitaliy Kaurov Aug 25 '12 at 8:33
add comment

1 Answer

up vote 10 down vote accepted

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

share|improve this answer
    
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? –  Sjoerd C. de Vries Aug 25 '12 at 7:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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