2
messagebox.askyesno(0.0,'"{0}"{1} \n {2}\n'.format(search_analyte.get(),' is  not in the database.','Add,if appropriate'))
        print (str(messagebox.askyesno()))
        if messagebox.askyesno() == True:
            open_second()
        else:
            open_first()

In this snippet of code the askyesno messagebox opens. If I click 'yes' once, nothing happens, if I click it a second time, 'True' is printed to the console(just added to see what I was returning), if I click it a third time, the messagebox closes and the correct notebook page opens. The same behaviour occurs with 'no'. First click, nothing, messagebox remains open but text within the message box disappears leaving only yes, no. The second time False is printed to the console, box remains open, third time, the box closes and the correct notepook page is open. Can someone explain what I have done incorrectly please

user1478335
  • 1,769
  • 5
  • 25
  • 37
  • the print statement that I inserted to see what was being returned generates one of the'non-events' i.e. message disappearing from messagebox, but remaining open until pressed again. So the question is why yes or no require two clicks to execute the full conditional – user1478335 May 13 '13 at 13:56
  • Can you write a complete, small program that illustrates this? I'm wondering if you're forgetting a step such as running mainloop, or maybe you're using threads? – Bryan Oakley May 13 '13 at 17:22
  • Will get on to it. Thanks for responding – user1478335 May 14 '13 at 10:32
  • Removing all of the other functionalities of the widget leaving only the add changed the behavious of the messagebox to what it should do! Cannot reproduce the error. I will start adding back everything and see which causes the problem – user1478335 May 14 '13 at 11:51
  • I am not allowed by stackoverflow to submit the code as a new question, informs me that is doesn't reach the standard required. With the comment facility would exceed the length. How can I do this otherwise? Can now reproduce the error – user1478335 May 15 '13 at 10:16
  • You should be able to edit this question. – Bryan Oakley May 15 '13 at 11:08

1 Answers1

5

In the code you posted, you are opening three dialogs. Every time you call askyesno you will get a dialog. You need to call askyesno once, save the value that it returns, then use that value in your test.

result = messagebox.askyesno(...)
if result:
    ...
Community
  • 1
  • 1
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685