Converted checkbox logic to python