TVTropes defines this as the Not-So-Innocent Whistle
In media of all types, especially comics and cartoons, the "innocent" whistle is a main staple, often played for humor. Alice, feeling mischievous, decides to, say, throw a snowball at Bob. Bob is knocked off his feet. He pulls himself up and spins around to see no one around in the area but Alice, who puts her hands behind her back and lifts herself up onto her tiptoes and back down several times while whistling. Sometimes Alice would be also be twiddling her thumbs, point her eyes upward/away, putting her hands in her pockets, or a halo would appear above her head — or any combination thereof. In comics, usually only a single note symbolizing the whistle is written. The Not-So-Innocent Whistle can also happen after suppressing a traumatic moment, or any other instance of hiding something
It cites one of the first usages as:
One of the earliest examples is in the movie M, where the child killer whistles the tune "In the Hall of the Mountain King" right before he tracks down one of his victims. He pauses and breaks it up at odd parts in the song, giving a sense of wrongness. This tic ends up being how the other criminals identify him and eventually hunt him down.
Other examples in the site are a bit more comedic...