1
$\begingroup$

I have 2 InputFields and 2 Buttons. I would like that when the user clicks the Pi Button or -Pi Button, that value will be assigned to that InputField only where the cursor was (either the first input field or the second).

Button["Range", (DialogInput[{range1 = 0, range2 = 0}, 
Column[{"Enter the Range", 
 Panel[Column[{InputField[Dynamic[range1], Number], 
    InputField[Dynamic[range2], Number], 
    Button["-Pi", (range2 = -3.14159;)], 
    Button["Pi", (range1 = 3.14159;)]}]]}]]), Method -> "Queued"]

Mathematica graphics

$\endgroup$

1 Answer 1

3
$\begingroup$

For your usage, you could simply use a PasteButton[] instead.

Button["Range", (DialogInput[{range1 = 0, range2 = 0}, 
Column[{"Enter the Range", 
 Panel[Column[{InputField[Dynamic[range1], Number], 
    InputField[Dynamic[range2], Number], 
    PasteButton["-Pi", -3.14159, Appearance -> Automatic], 
    PasteButton["Pi", 3.14159, Appearance -> Automatic]}]]}]]), 
Method -> "Queued"]
$\endgroup$

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.