How to assign a specific color scale to all specific objects in the scene
You only want to iterate thru mesh (or meta i suppose) objects that can have a material.  Here is a sample, changing scene.bool removes material if False, or adds a new material to each object with a differing shade of green.

import bpy
from bpy.props import BoolProperty

def toggle_bool(self, context):

    val = 0.0
    for o in self.objects:
        if o.type not in {'MESH', 'META'}:
            continue

        if self.bool:
            print(o, val)
            mat = bpy.data.materials.new("BSDF")
            mat.diffuse_color = (val, 1, val)

            o.active_material = mat
            val += 0.1
        else:
            o.active_material = None

bpy.types.Scene.bool = BoolProperty(update=toggle_bool)