Why does an atom have a tendency to gain/lose electrons?

An atom that does not have a full valence shell will have a tendency to gain or lose valence electrons in order to achieve a stable electronic configuration.