Does your pupil opening and closing have anything to do with it focusing on a more distant object?
The size of your pupil does not depend on the distance to an object. It depends only on how bright the scene in front of you is. But the size of your pupil does affect your ability to focus. When it is relatively dark and your pupil is wide open, the whole lens of your eye is involved in light gathering. Focusing becomes very critical and you have very little depth of focus. Moreover, if your lens isn’t perfect, you will see things as blurry. But when it is bright out and your pupil is small, you are only using the center portion of your lens and everything is in focus. That’s why it is harder to focus at night than during the day. When you squint, you are artificially shrinking the effective diameter of the lens in your eye and increasing your depth of focus. Unfortunately, you are also reducing the amount of light that reaches your eye. If you look through a pinhole in a sheet of paper, you will find everything in focus, although it will appear very dim.