'Is there a way to simplify the creation of all possible (length x height) grids?

Here's my code for a 4x4 grid to better explain my problem:

    #The "Duct-Tape" solution
    for box0 in range(0,2):
        for box1 in range(0,2):
            for box2 in range(0,2):
                for box3 in range(0,2):
                    for box4 in range(0,2):
                        for box5 in range(0,2):
                            for box6 in range(0,2):
                                for box7 in range(0,2): #0 = OutBag, 1 = InBag
                                    for box8 in range(0,2):
                                        for box9 in range(0,2):
                                            for box10 in range(0,2):
                                                for box11 in range(0,2):
                                                    for box12 in range(0,2):
                                                        for box13 in range(0,2):
                                                            for box14 in range(0,2):
                                                                for box15 in range(0,2):
                                                                    totalGrids.append([[box0,box1,box2,box3],
                                                                                         [box4,box5,box6,box7],
                                                                                         [box8,box9,box10,box11],
                                                                                         [box12,box13,box14,box15]])

What's a way to make something like this for a length x height size grid?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source