As mentioned above, Western music has not remained static through the centuries, either. It has changed and evolved as composers experimented with new sounds, ideas, and even new or evolving instruments.
Medieval European music, like many Non-Western traditions, was modal. This means that a piece of music was not in a particular key based on a major or minor scale. Instead, it was in a particular mode. A mode may look very much like a scale, since it lists the notes that are "allowed" in the piece of music and defines the tonic of the music. But a mode is usually also a collection of melodies, melodic phrases, or patterns that are found in that mode and not others (since the various modes are more different from each other than the various scales). Modes also may imply or suggest specific moods or they may be meant to have particular effects on the character of the listener.
Different keys may also evoke different moods, but the main purpose of a key is to define the chords (Chords) and harmonic progressions that will be expected from a piece of music.
From the Renaissance to the present day, most Western music has tended to be tonal. Tonal music is music in which the progression of the melody and harmony gives the strong feeling that the piece has a note and chord that are its "home base", so to speak (the tonic of the key). Think of a very familiar tune, perhaps "Row, Row, Row your Boat" or "Happy Birthday to You". Imagine how frustrating it would be to end that tune without singing the last note or playing the final chord.
If you did this, most people would be so dissatisfied that they might supply that last note for you.
That note is the tonal center of the tune, and without it, there is a feeling that the song has not reached its proper resting place. In tonal music, just about any melody is allowed, as long as it fits into the harmonies as they wander away from and then head back to their home base. Most Western tonal music is based on major and minor scales, both of which easily give that strongly tonal feeling.
Some other scales, such as blues scales , also work well within a tonal framework, but others, such as whole-tone scales, do not.
Most of the Western music that is popular today is tonal, but around the beginning of the twentieth century, composers of "Classical" or Art music (see below) began experimenting with methods of composing atonal music. "Atonal" literally means "not tonal". As the name implies, atonal music treats all notes and harmonies as equal and in fact tries to avoid melodies and harmonies that will make the piece sound tonal. One type of atonal music is twelve-tone music, which seeks to use each of the notes of the chromatic scale (pg 123) equally. Other pieces may even dispense with the idea that music has to consist of notes; compositions may be collections of sounds and silences. Since the music is not organized by the familiar rules of Western music, many people have trouble appreciating atonal music without some help or study.
Music can be more or less tonal without becoming completely atonal, however. Music that does not stray at all from its key is called diatonic. Many Western children's songs, folk songs, and pop songs are in this category. But composers often add some notes or even whole sections of music that are from a different key, to make the music a little more complex and interesting. Music that goes even further, and freely uses all the notes of the chromatic scale (pg 123), but still manages to have a tonal "home", is called chromatic. Music that has more than one tonal center at the same time (Ives was particularly fond of this composition technique) is called polytonal.