What is the name for the music or sound played when a key character appears in a play, movie or show; like in "Peter and the Wolf"?
I think the word you're looking for is leitmotif:
A recurrent theme throughout a musical or literary composition, associated with a particular person, idea, or situation.
The tune associated with a particular character is called that character's musical theme, theme music, or signature song.
From the Wikipedia article on Peter and the Wolf, for example:
Each character in the story has a particular instrument and a musical theme:
Hunters: woodwind theme, with gunshots on timpani and bass drum
Peter: instruments (including violin, viola, cello, and bass)
Wolf: French horns
And similarly, quoting from the Wikipedia article on "theme music":
The phrase theme song or signature tune may also be used to refer to a signature song that has become especially associated with a particular performer or dignitary; often used as they make an entrance.
I think I may have found it: "leitmotif."
From the Wikipedia entry a leitmotif is "is a "short, constantly recurring musical phrase" associated with a particular person, place, or idea."
Although several answers have identified "leitmotif," if the music in question is more brief it could be called a
OED describes a fanfare as:
A short ceremonial tune or flourish played on brass instruments, typically to introduce something or someone important: a specially composed fanfare announced the arrival of the Duchess
The relevant definition for flourish cites "fanfare" but another definition provides color:
A bold or extravagant gesture or action, made especially to attract attention: with a flourish, she ushered them inside
motif or motive (less common) - This would probably be my second choice. It's a general musical term, basically synonymous with theme.
leitmotif - Has a specific technical meaning in music theory. While all leitmotifs are themes used to represent characters and ideas, not all such motifs are commonly called leitmotifs, since leitmotif carries connotations of a certain musical tradition, from Richard Wagner to the Lord of the Rings soundtrack. If you're looking for something general, this is not necessarily the best word to choose. The word also may not be as recognizable to a wider audience.