die Tonart
key
In music, the tonal center of a piece, determined by a tonic and a mode (major or minor). The key establishes the harmonic foundation.
Das Lied steht in der Tonart G-Dur.
The song is in the key of G major.

key / tone
Loading your saved state.
key
In music, the tonal center of a piece, determined by a tonic and a mode (major or minor). The key establishes the harmonic foundation.
Das Lied steht in der Tonart G-Dur.
The song is in the key of G major.

The word is made up of 'der Ton' (the tone/sound) and 'die Art' (the kind/type). So it literally means 'the kind of tone', which fits both the musical structure and the tone of an utterance.
Die fröhliche Tonart des Liedes passte nicht zu seiner traurigen Stimmung.
The cheerful key of the song did not match his sad mood.
You can recognize the musical meaning from words like 'Lied' (song), 'Stück' (piece), 'Dur' (major), or 'Moll' (minor). The figurative meaning refers to the manner of communication and often appears with words like 'Stimme' (voice), 'Antwort' (answer), or 'Gespräch' (conversation).
In welcher Tonart ist dieses klassische Stück geschrieben?
What key is this classical piece written in?
In a musical context, the preposition 'in' is almost always used to indicate the key. A piece of music 'steht in' (is in) a certain key.
Der Pianist begann, das Stück in einer anderen Tonart zu spielen.
The pianist began to play the piece in a different key.
When referring to tone of voice, 'Tonart' (tone) is often combined with descriptive adjectives such as 'scharf' (sharp), 'freundlich' (friendly), 'bestimmt' (firm), 'ironisch' (ironic), or 'befehlend' (commanding).
Er wechselte in eine freundlichere Tonart, als er merkte, dass er zu streng klang.
He switched to a friendlier tone when he realized that he sounded too strict.
mood / atmosphere
'die Stimmung' and 'die Tonart' can both have something to do with music or with a certain tone in a situation. The most important difference is in how they are used. In music, 'Tonart' means the key of a piece of music, for example major or minor. 'Stimmung' can mean the correct tuning of an instrument in music, but also more generally the atmosphere in a room or group. Figuratively, 'Tonart' can also mean the way someone speaks, that is, whether something sounds friendly, sharp, or ironic. Learners may confuse the words because both are connected with 'Ton' (tone/sound) and feeling. For atmosphere, you usually say 'Stimmung'; for the musical key of a piece or the tone of an utterance, 'Tonart' is more precise.

Frau Müller wählt für das Lied eine hellere Tonart.
Ms. Müller chooses a brighter key for the song.
Vor dem Konzert prüft der Musiker die Stimmung seiner Gitarre.
Before the concert, the musician checks the tuning of his guitar.