Posterior capsular opacification (PCO) is a common complication following cataract surgery, which can lead to a significant vision loss. This study introduces a facile method for developing a metformin-derived hydrogel (HCM6) stabilized by dynamic covalent bonds among natural polymers. This hydrogel demonstrates antifibrotic properties, on-demand drug release, pH responsiveness, injectability, and self-healing capabilities. Our in vitro experiments confirmed that the HCM6 hydrogel exhibits excellent biocompatibility, inhibiting lens epithelial cell migration, and transforming growth factor-2β (TGFβ2)-induced α-smooth muscle actin (α-SMA) expression in lens epithelial cells. In vivo studies conducted in a rat extracapsular lens extraction (ECLE) model revealed that HCM6 significantly suppressed PCO after 21 days of implantation with no observed pathological effects on surrounding tissues or the optic nerve. According to our experimental results, the inhibitory mechanism of PCO may be attributed to metformin's suppressive effect on lens cell migration, epithelial-mesenchymal transition (EMT), and lens fiber formation. In summary, the long-acting, controllable, and on-demand release characteristics of the HCM6 hydrogel not only provide an effective strategy for preventing PCO but also offer new avenues for treating undesirable proliferative conditions in ophthalmology and beyond.