0

During the execution of my programme this function is called several times, but it only works the first time that I execute it. The second time that the function is called the GUI is blocked at the ShowModal call and the execution of the script stops, but no errors are shown anywhere.

Here is the code:

def MessageDialog(a, message, title , options):
    dlgQuestion = wx.MessageDialog(None, message, title, options)
    response =  dlgQuestion.ShowModal() == wx.ID_YES

    return response

wxPython version 3.0.3

python version 3.4.4

0.S. is Windows 7

Bobbick
  • 255
  • 3
  • 10
  • Sorry @Jean-FrançoisFabre I clicked the enter button too quickly. Edited to add it. – Bobbick Jan 16 '17 at 16:13
  • you mean that the dialog doesn't show? if it doesn't how do you know that the code is blocked here? – Jean-François Fabre Jan 16 '17 at 16:14
  • @Jean-FrançoisFabre I added a print("x") after each line of code to check where it stopped. The last print("x") that is shown in the console is the one right before the call to dlgQuestion.ShowModal(). I also tried breaking the call to ShowModal and the comparison with wx.ID_YES into different lines but the issue still happened before the call to ShowModal. In one occasion the message was shown, but the GUI was blocked right after I clicked the button in the message so the final result was the same. – Bobbick Jan 16 '17 at 16:26
  • Dialogs need to be explicitly Destroyed when you are done with them. Does adding a call to `dlgQuestion.Destroy()` help? If not, please report the platform and wxPython version you are using, and also add a small runnable sample that demonstrates the problem. – RobinDunn Jan 16 '17 at 23:15
  • @RobinDunn I tried also destroying the message dialog but the same issue arises. It works fine the first time but the second time the programme does not reach the Destroy command. I will edit my original question to add information about the versions. – Bobbick Jan 17 '17 at 11:51
  • 2
    What is the rest of the program like? Has the `wx.App` object's `Mainloop` method been called? Is the above code running in the same thread that created the `wx.App` object? What is happening between calls to the above code? (If you supply a small runnable sample that demonstrates the problem that would be best.) – RobinDunn Jan 18 '17 at 01:24

0 Answers0