We perform the first-principles calculations within the framework of density functional theory to determine the electronic structure and optical properties of P-doped and B-doped silicon nanotubes. The results indicate that the electronic structure and optical properties of P-doped and B-doped silicon nanotubes are sensitive to the impurity composition. In particular, when doped with P or B, obviously the band gap decreases and the conductivity enhanced, the P-doped and B-doped silicon nanotubes displays a closer band structure and the unit cell volume of doped silicon nanotubes increased than before doping, the change depends on the doping charge and Si-Si bond length dSi-Si. Moreover, the dielectric constant decreases and increased when doped P and B, the optical absorption peak obviously has a blue shift and red shift respectively. The calculated results provide important theoretical guidance for the applications of Uv detector and the solar cell in optical detectors.