Button press event triggers multiple times?

My daughter was working on a simple game, and it’s behaving very strangely. Pressing the “A” button once in the emulator often triggers the “on button pressed” handler multiple times. Here’s a simplified version with some console logging added:

In short, you’re supposed to press the A button when the donut shows up to gain a point. Pressing the button when there’s no donut loses a life. (The original game had two donut types and longer intervals between them, I simplified it for debugging.)

Oddly, the emulator often seems to produce multiple A button events, resulting in losing lives, and logging shows that these are all at the same timestamp:

update, time: 1
A button, time: 756
A button, life: 4
stopping countdown
countdown stopped
A button, time: 829
A button, life: 4
A button, time: 829
A button, life: 3
A button, time: 829
A button, life: 2
A button, time: 829
A button, life: 1
A button, time: 829
A button, life: 0

While it wouldn’t be too hard to work around this with some added timer logic, this looks as if it might be an emulator bug. Has anyone else seen this happening, or can you reproduce it? It doesn’t happen consistently, but I’ve seen it now on two separate computers with two different mice, so I don’t think it’s a hardware issue with a flaky mouse.

In case it helps, using the space bar as the “A” button on the emulator seems to work fine, I couldn’t reproduce the problem that way. The multiple events only seem to happen when using mouse clicks on the onscreen “A” button.

Playing it on a PyGamer Arcade also works fine.