When I read the question, I quickly thought that a memory cell could be involved somewhere in the solution. But actually, a memory cell (with one input inverted) is already all you need!
Imagine that the comparator comes from your minecart and the button is just your button. The redstone lamp is the output for emptying the minecart.
When the minecart arrives with items, it turns on the comparator, which turns off the redstone lamp on the left and the redstone dust. Nothing else happens, because the memory cell still holds its state, that's the point of a memory cell.
When you now press the button, the bottom redstone torch and the left repeater turn off, which allows the top right redstone torch to turn on (since it's also not deactivated by the redstone line anymore), which turns on the output and the repeater on the right.
When the button input ends, the bottom redstone torch still does not turn on, because the right repeater is still on. Again, what a memory cell is supposed to do.
Only when the comparator turns off and the left redstone torch and the dust turn on again, then the top right redstone torch turns off again, deactivating the right repeater, activating the bottom redstone torch and the left repeater.
- If the minecart empties before the button turns off, the input turns off rightaway (with 3 ticks delay).
- If you press the button while the minecart is empty or not there, nothing happens.
- Spamming both inputs in certain ways very quickly and very often might cause the torches to burn out, but that should be extremely unlikely in your usecase and probably very easy to fix (it might even fix itself).