Display Options
In student notebooks, quizzes are rendered by
display_quiz(). This function is called
automatically by the code cells that CreateQuiz
generates during nbgrader generate_assignment, but you can also call it
directly when working with quizzes outside the nbgrader pipeline.
- nbgrader_jupyterquiz.display_quiz(ref, num=1000000, shuffle_questions=False, shuffle_answers=True, preserve_responses=False, border_radius=10, question_alignment='left', max_width=600, colors=None, load_js=True, grade_id=None)[source]
Display an interactive quiz in a Jupyter notebook.
Parameters
- reflist or str
Question list, DOM element id (
#name:tag), URL, or file path.- numint, optional
Maximum number of questions to show.
- shuffle_questionsbool, optional
Randomise question order on each display.
- shuffle_answersbool, optional
Randomise answer order on each display.
- preserve_responsesbool, optional
Keep student responses visible after answering.
- border_radiusint, optional
CSS border-radius in pixels.
- question_alignmentstr, optional
One of
'left','center','right'.- max_widthint, optional
Maximum quiz width in pixels.
- colorsdict or str, optional
CSS variable overrides, or
'fdsp'for the alternate palette.- load_jsbool, optional
Whether to inline the JavaScript source.
- grade_idstr, optional
Nbgrader
grade_idof the host task cell. When set, the JS recorder persists student responses to aresponses.jsonsidecar file so an autograded test cell can read them vianbgrader_jupyterquiz.autograde.grade_quiz(). WhenNone(the default for non-nbgrader callers), the recorder is a no-op.
Reference source
The ref argument determines where question data is loaded from.
Type |
Description |
|---|---|
|
A Python list of question dictionaries (see Quiz Syntax). |
|
A CSS identifier. The element is looked up first by |
|
An HTTP/HTTPS URL pointing to a JSON file. |
|
A local file path to a JSON file. |
Display parameters
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
all |
Maximum number of questions to show. A random subset is chosen each
time the cell is executed. Incompatible with |
|
|
|
Randomise question order each time the cell is executed. Incompatible
with |
|
|
|
Randomise answer option order each time the cell is executed. |
|
|
|
Keep student responses visible after answering. Requires fixed question
order ( |
|
|
|
CSS |
|
|
|
Text alignment inside question boxes. One of |
|
|
|
Maximum width of the quiz widget, in pixels. |
|
|
default palette |
Colour customisation. Pass |
|
|
|
Whether to inline the JavaScript source. Set to |
Colour customisation
Pass a dictionary to colors to override individual CSS variables. Any
variables not included in the dictionary retain their default values.
from nbgrader_jupyterquiz import display_quiz
display_quiz(questions, colors={
"--jq-multiple-choice-bg": "#1a1a2e",
"--jq-correct-color": "#00b894",
})
Pass colors="fdsp" to switch to the alternate fdsp palette entirely.
Available CSS variables:
Variable |
Default |
Description |
|---|---|---|
|
|
Background of single-choice question boxes |
|
|
Background of many-choice question boxes |
|
|
Background of numeric question boxes |
|
|
Answer button background |
|
|
Answer button border colour (88 % opacity) |
|
|
Answer button text colour (default and deselected state) |
|
|
Answer button inset shadow colour |
|
|
Numeric input field background |
|
|
Numeric input field label colour |
|
|
Numeric input field shadow colour |
|
|
Background of string-type question boxes |
|
|
Highlight colour for correct answers |
|
|
Highlight colour for incorrect answers |
|
|
Question and answer text colour |
|
|
Link colour inside questions |
Capturing responses
Persistent answer capture for graded quizzes is handled automatically by placing the quiz inside a Manually Graded Task cell — the preprocessor wires up the recorder and autograder for you. See Graded Quizzes.