The honest answer to how to straighten a leaning tree depends entirely on the size of the tree and the cause of the lean. A newly planted sapling or a small ornamental that shifted position recently can sometimes be staked and guided back upright if the root system is still intact. This is a reasonable DIY approach for trees under a few inches in diameter that have not been in the ground long.
For an established tree, straightening is not a realistic option through any homeowner method. What professional arborists can offer for certain salvageable situations is cabling and structural support systems, which stabilize a leaning tree rather than reversing the angle. Cabling does not fix a failing root system, but for a tree with a structural lean and otherwise sound wood, it can reduce the risk of limb failure and extend the tree’s safe lifespan.
For leaning trees where the root system is compromised, professional tree removal before failure is always safer and less costly than removal after one.