The invention relates to a medicine box, in particular to a medicine box with an automatic counting function, which belongs to the field of medical and health instruments and comprises a main body and a medicine frame, wherein the medicine frame comprises a counting mechanism with the counting function. A technical mechanism achieves medicine quantity recording through an optical control principle, a medicine mechanism comprises a switch, a sliding block, a base and an elastic component, one end of the sliding block is a rectangular plate, the other end of the sliding block is a slanted plate, the rectangular plate end of the sliding block is close to an optoelectronic switch, the slanted plate end of the sliding block is far away from the optoelectronic switch, and two sides of the sliding block extend respectively to form flank baffles which are intersected with the rectangular plate in a cross-shaped mode. The elastic component is arranged between the optoelectronic switch and the flank baffles of the sliding block, and the counting function is achieved by means of the fact that the sliding block slides in the middle of the optoelectronic switch when a sliding block slanted plane feels medicine weight. The medicine box has the advantages of being simple in structure and accurate and reliable in counting, greatly improves safety and convenience of medicine storage, avoids loopholes and management risks caused by manual operation, saves labor cost and management cost, and is applied to medium and large hospitals, drugstores and the like.