A series of polyimide photocatalysts with different polymerization degrees were prepared by thermal condensation of melamine and pyromellitic dianhydride at different condensation temperatures between 250 °C and 350 °C. Fourier transform infrared (FT-IR) spectra, X-ray powder diffraction (XRD) and scanning electron microscopy (SEM) revealed that the polymerization degree increased with increasing condensation temperature. UV–Vis absorption spectra showed that the bandgap energy was lineally decreased with the increase of temperature. The theoretical calculations indicated that the level of conduction band downshifted and valence band upshifted upon the bandgap narrowing. Photocatalytic results displayed that the sample with moderate bandgap exhibited the highest H 2 evolution activity, which adapted the balance among many factors such as light absorption, band potentials, crystallinity, particle size and surface area.