From what I can see it looks like it's because you are calling newName.ShowModal() twice in your code.
In the first call to DoModal in your if statement, a dialog is created and if the user presses ok and has entered some text the dialog is destroyed and your while loop breaks out.
If the user presses ok after entering no text, the dialog is destroyed, your while loop reiterates and the first call to ShowModal is called again. OK so far, I assume this is the behaviour you want.
But if the user closes the initial text box with cancel, your code drops to the elif statement where DoModal is called a second time, creating a 2nd dialog.. In the 2nd call, whether the dialog returns via ok or cancel it will be destroyed.
So it is the call to DoModal in the elif that is the problem!
What you need to do is alter your code so that you're making one call to DoModal and then see what value was returned..
So I'm guessing you'd need to do something like this:
def OnNewButton(self,event):
error=1
while error==1:
newName = wx.TextEntryDialog(self, 'Question?:','Title')
newName.SetValue("")
retVal = newName.ShowModal()
if retVal == wx.ID_OK:
if len(newName.GetValue().strip())!=0:
error=0
self.Destroy()
elif retval == wx.ID_CANCEL:
error=0
newName.Destroy()
Hope that solves your problem!
Cheers for now,
Jas.