Ultra-wide band gap (UWBG) perovskite materials have received a lot of attention in recent years, and the triple perovskite Ba2K2Te2O9 is one of the materials in this category, while its band gap greater than 3.4 eV limits its application in the field of optics since it can only absorb ultraviolet light well. Here, this work selected three elements of B, C, and N, which are located in the same period of the chemical periodic table, to dope Ba2K2Te2O9 at suitable oxygen doping sites. Moreover, the formation energy, electronic structure, and optical properties of Ba2K2Te2O9 before and after doping were calculated by first principles through high-performance clusters. We have found that the crystal system doped by the above three elements has different degrees of reduction in the forbidden bandwidth, which is very helpful to improve its optical properties. From the results, the crystal system doped by B and C has a good red-shift phenomenon, and its light absorption range extends to visible light and even part of infrared light, and this doping crystal system can be used as good photovoltaic material in the future.