Instead of measuring the peak colour of a star, the more common way in astronomy nowadays to determine temperature is to determine the spectral class of a star.
When astronomers pass the light of a star through a spectrometer, they get a spectrum of the star. The spectrum looks like a regular rainbow of colours—except that there are dark lines in it, absorption lines.
Here is a spectrum of our sun:
Each chemical element absorbs light in particular wavelengths (particular colours) when electrons in the atoms of the element move to a higher energy level. There are different (but precise) energy levels for the electrons and therefore different wavelengths absorbed. Each chemical element therefore has a specific signature of absorption lines like a barcode.
If that element is in the cool atmosphere of a star, those atoms will absorb the light from the star at those wavelengths and produce the set of absorption lines that we can observe, even if the star is at a great distance.
To produce certain spectral lines, a star must be hot enough to excite the electrons out of a particular state but not too hot to ionise a significant fraction of the atoms. In ionised atoms, the electrons are removed, so there are no electrons to excite, so no spectral lines.
Therefore astronomers can determine a star’s temperature by the strength of its various spectral lines.