By means of variable-temperature scanning tunneling microscopy and spectroscopy we studied the thickness-dependent roughening temperature of Pb films grown on Cu(111), whose electronic structure and total energy is controlled by quantum well states created by the spatial confinement of electrons. Large scale STM images are employed to quantify the layer population, i.e., the fraction of the surface area covered by different Pb thicknesses, directly in the real space as a function of temperature. The roughening temperature oscillates repeatedly with bilayer periodicity plus a longer beating period, mirroring the thickness dependence of surface energy calculations. Conditions have been found to stabilize at 300 K Pb films of particular magic thicknesses, atomically flat over microns.