When you create the new panel also it is necessary to check that the panel has not been created earlier. As consider that when you press a key on the keyboard, the condition "if (key_p)" is equally True in the several iterations of a cycle "while".