As a common pest in wheat flour, Tribolium castaneum Herbst (Coleoptera: Tenebrionidae) is responsible for economic losses and potential risks to food safety. This study aimed to investigate the feeding preferences of T. castaneum on wheat flour stored at different temperatures, analyzed the key flavor compounds influencing its feeding preferences, and laid down the foundation for the development of new T. castaneum attractants and repellents. According to results, in the early storage period, T. castaneum showed a higher preference for feeding on wheat flour stored at higher temperatures, but this trend decreased over the storage time with a preference shift towards the flour preserved at lower temperatures. The findings from GC-MS revealed changes in the types and concentrations of volatile components in wheat flour during storage. PCA and correlation analysis suggested that compounds such as 2-methyldodecane, 3-methyl-3-ethylheptane, benzaldehyde, decanal, and n-hexanol exhibited potential attractiveness to T. castaneum. Conversely, 2-methyloctane, 2,5-dimethyldodecane, and dodecane were identified as potential repellents. At different storage temperatures, benzaldehyde and 2-methyloctane displayed consistent attractant and repellent effects, indicating their potential as effective components for attractance and repellence. Overall, our work shed the light regarding the feeding preference of T. castaneum on wheat flour stored at different temperatures from the perspective of volatile component variations, and provided a theoretical basis for the development of novel attractants and repellents.