In this case it's a layout display option.
The toggle
option for
UILayout.prop
toggle (int in [-1, 1], (optional)) – Use toggle widget for boolean values, or a checkbox when disabled (the default is -1 which
uses toggle only when an icon is displayed)
layout.prop(context.object, "some_bool_prop", toggle=True)
is to make the boolean property appear like a button in the UI, rather than a checkbox. Please note that context
is always passed to a draw method, so there is never a need to see bpy.context
To do the same with an operator, there is the bpy.ops.wm.context_toggle()
operator, (Seen often in the keymaps)
op = layout.operator("wm.context_toggle")
op.data_path = "object.some_bool_prop"
where the data path is relative to context.
An operator is displayed as an embossed button by default in the UI, setting
op = layout.operator("wm.context_toggle", emboss=False)
will make it more link like.
BoolVectorProperty
The lock_rotation
is a vector property with a boolean for each axis.

Example setting only the X axis (index = 0) lock. New draw method for Text Editor > Templates > Pythons > UI Panel Simple
The panel only polls if there is a context object. This ensures that the object is the one that has the properties being displayed. Not doing so will result in an error, generally notable by seeing 'Noneor
NoneType` in the error message
Hide Panel With Python
def draw(self, context):
layout = self.layout
obj = context.object
row = layout.row()
row.prop(obj, "lock_rotation", index=0, toggle=False)
row.prop(obj, "lock_rotation", index=0, toggle=True)
op = row.operator("wm.context_toggle")
op.data_path = "object.lock_rotation[0]"
op = row.operator("wm.context_toggle", emboss=False)
op.data_path = "object.lock_rotation[0]"