You need a buffer.

First you draw everything into your buffer picture (which is invisible), then you draw the whole buffer to the screen. That prevents flickering, but costs a bit of performance (But it's worth it ).