OpenerView works as expected in this:

OpenerView[{"This is the question", "This is the answer"}, False],

Yet when I put it in a loop, it has no effect:

OpenerView[{"This is the question", "This is the answer"}, False], 3]

The "hello" prints fine, three times.

All I'm seeking to do is to

  • print "This is the question" on the screen (1), so that
  • the user needs to click to show "This is the answer" (2), and then
  • they get a button saying "Next question" (3), and
  • repeat (4).

The only input I need from the user is mouse clicks: to show each answer, and then once they've read it to move on to the next question.

1-2 can be got in isolation using OpenerView.

3 can be got with

ChoiceDialog["Next question", Modal -> True];

which works great in for example

ChoiceDialog["Next question", Modal -> True];

But I can't get OpenerView to work in a loop so something like the following also fails to give the required output:

 Do[Print["hello ", i];
 ChoiceDialog["Next question", Modal -> False];
 OpenerView[{"This is the question", "This is the answer"}, False], 3]

I'd be grateful in advance for any help with this. I'm trying to keep it as simple as possible, but there must be something I don't understand with the functioning of OpenerView.

  • $\begingroup$ Look at CellPrint. Namely, you have to do CellPrint[OpenerView[...]]. $\endgroup$
    – Domen
    Oct 1 at 18:06
  • $\begingroup$ Or even just Print[OpenerView[...]]. $\endgroup$
    – Domen
    Oct 1 at 18:28
  • 1
    $\begingroup$ Notice that from Do's documentation: "Unless an explicit Return is used, the value returned by Do is Null." Most likely you want to use Table instead of Do, and then use something like Column to make it look nice. If you are generating a large number of OpenerViews, then I would use CellPrint. $\endgroup$ Oct 1 at 20:15


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.