1
$\begingroup$

This prints "This is the question", and then when you click on it it prints "This is the answer":

EventHandler["This is the question",
{"MouseClicked" :> Print["This is the answer"]}]

This opens a new notebook in which it prints "This is the question" followed by "This is the answer".

 NotebookPut[
 Notebook[{Cell["This is the question", "Text"],
 Cell["This is the answer.", "Text"]}]];

But how can I open a new notebook and print "This is the question" and then only print "This is the answer" when someone clicks on "This is the question", i.e. get the same effect as with the first code but in a newly opened notebook?

$\endgroup$

1 Answer 1

1
$\begingroup$

I've now found an answer to this. It's to use CreateDocument rather than NotebookPut, like this:

 CreateDocument[EventHandler[
 TextCell["This is the question"],
 {"MouseClicked" :> Print["This is the answer"]}]];
$\endgroup$
0

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.