. When you get weird errors like yours, it usually involves timing. I'll bet if you run your code standalone 100 times, a few times it will work when the system is under different load conditions. I would guess the way alot of programmers like to destroy a window (and unwittingly the Mainloop), then recreate it, with different widgets, that is a likely culprit. The debugger is probably keeping the eventloop alive somehow.