Pentax film cameras, and perhaps early digital units, had a mechanical means of detecting the aperture position of older non-A lenses. There is a petition thread asking Pentax to restore this capability. I personally don't think it will happen for marketing reasons, but hope springs eternal.
K-mount lens have springs that pull the aperture blades to the smallest opening. When you mount these lenses, the body pushes against these springs to open the blades to their largest opening. If the lens has an aperture ring, there are mechanical stops that prevent the lens from closing smaller than the stop set on the ring. When the camera's shutter is released, the body allows the lens to close to this mechanical stop.
K-mount lenses with 'A' capability (A-series and newer, including all those lenses without an aperture ring) are detected by the camera body. The body is also able to detect the aperture range for these lenses. When these lenses are in the 'A' position (lenses without aperture rings are always in the 'A' position), the camera body doesn't just let the lens close to its mechanical aperture stop, but knows how far to let the aperture controlling lever move to achieve a specific stop.
To summarize, with non-A lenses, the lens determines where to stop the lens aperture movement, but with A lenses, the body determines where to stop the lens aperture movement.
The issue with using older non-A lenses on digital camera bodies has to do with exposure metering. Because the lens is held wide open when the scene is metered, and the body has no idea how much the exposure will be reduced by the aperture ring setting, Pentax has added a step using the green button whereby the lens is allowed to close the aperture to its set value before the meter is activated. Thus the term 'stop down metering'.
There IS a way to non-destructively modify a non-A k-mount lens and the camera body to approximate the operation of an A-series lens. Exposure will typically be within 1 stop, and the error will always be on the over exposure side.
Look at the post in this link, then scroll down a couple posts if you want to see pictures. While I am using a KA 50mm f/1.7 lens, I lose all 'A' features when I mount the lens on my macro converter (or my bellows unit). It effectively becomes an M-series lens. These posts show how I get around that limitation.
PK/A extension tubes? - PentaxForums.com