When the player presses down on a valve, it changes the length of the tubing, which in turn changes the pitch of the sound. The different combinations of valves that can be pressed down result in different notes being played.
The timbre, or quality, of the sound produced on the trumpet is influenced by a number of factors, including the player's embouchure (the way their lips and mouth are positioned on the mouthpiece), the amount of air pressure they use, and the use of vibrato (a slight variation in pitch that adds richness to the sound).