insert_check_box method

insert_check_box(name, checked_value, size)

Inserts a checkbox form field at the current position.

def insert_check_box(self, name: str, checked_value: bool, size: int):
    ...
ParameterTypeDescription
namestrThe name of the form field. Can be an empty string. The value longer than 20 characters will be truncated.
checked_valueboolChecked status of the checkbox form field.
sizeintSpecifies the size of the checkbox in points. Specify 0 for MS Word to calculate the size of the checkbox automatically.

Remarks

If you specify a name for the form field, then a bookmark is automatically created with the same name.

Returns

The form field node that was just inserted.

insert_check_box(name, default_value, checked_value, size)

Inserts a checkbox form field at the current position.

def insert_check_box(self, name: str, default_value: bool, checked_value: bool, size: int):
    ...
ParameterTypeDescription
namestrThe name of the form field. Can be an empty string. The value longer than 20 characters will be truncated.
default_valueboolDefault value of the checkbox form field.
checked_valueboolCurrent checked status of the checkbox form field.
sizeintSpecifies the size of the checkbox in points. Specify 0 for MS Word to calculate the size of the checkbox automatically.

Remarks

If you specify a name for the form field, then a bookmark is automatically created with the same name.

Returns

The form field node that was just inserted.

Examples

Shows how to insert checkboxes into the document.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

# Insert checkboxes of varying sizes and default checked statuses.
builder.write("Unchecked check box of a default size: ")
builder.insert_check_box("", False, False, 0)
builder.insert_paragraph()

builder.write("Large checked check box: ")
builder.insert_check_box("CheckBox_Default", True, True, 50)
builder.insert_paragraph()

# Form fields have a name length limit of 20 characters.
builder.write("Very large checked check box: ")
builder.insert_check_box("CheckBox_OnlyCheckedValue", True, 100)

self.assertEqual("CheckBox_OnlyChecked", doc.range.form_fields[2].name)

# We can interact with these check boxes in Microsoft Word by double clicking them.
doc.save(ARTIFACTS_DIR + "DocumentBuilder.insert_check_box.docx")

See Also