If I go through a town, I will enter the town, drive in the town for a while, then drive out.
If I drive by a town, I will take a road that passes near the town, but does not enter the town at any point.
"I walked through the museum" = I entered the museum and walked around inside.
"I walked by the museum" = I walked outside the museum on my way to someplace else. I did not enter the museum.