The present invention discloses a pyrimidine or pyridopyridone compound as shown in formula (I) and an application thereof relating to the technical field of medicament preparation. The compound can selectively suppress cyclin-dependent kinases (Cdks) CFK4 and CDK6 with almost no suppression of the activity of the kinase CDK2. Thus, the compound can be used for various diseases caused by cell cycle control disorders involving CDK4 and CDK6, and particularly in the treatment of malignant tumors.