1

I have the following code, which should open a popup window. Now, if the user click "Yes" in the popup, it should show the main program window, and otherwise exit:

import tkMessageBox
from Tkinter import *

root = Tk()
root.withdraw()  # hide the main program window

if not tkMessageBox.askyesno("Title",
                             "Do you want to start the program now?"):
    # If the user pressed the 'No' botton
    root.destroy()
    exit(0)

print "test"

text = Text(root)
text.insert(INSERT, "Hello")
text.pack()

root.deiconify()  # show the main program window
root.mainloop()

When I run it and click on the "Yes" button in the popup, I see that "test" is outputted to the terminal, but the popup freezes and I don't see the main program window with the text element. I have looked at Tkinter TkMessageBox not closing after click OK, but it didn't help me. Does anybody have a solution to this problem?

martineau
  • 119,623
  • 25
  • 170
  • 301
Anders
  • 13
  • 4
  • Works fine for me using Python 2.7.13 (on Windows 7). – martineau Aug 26 '17 at 16:20
  • I use a mac with python 2.7.10. But I can't see what the difference should bee on mac and windows regarding the script? – Anders Aug 26 '17 at 16:29
  • 1
    You might do better with 2.7.13, but do you have an updated tcl/tk? See https://www.python.org/download/mac/tcltk/. – Terry Jan Reedy Aug 26 '17 at 16:36
  • Haven't worked on a Mac since July 2014, but as I recall, it was difficult to get a working/right version of `Tkinter` because OSX comes with a different version of Python installed (than the one I wanted to use). Regardless, this sounds like an OSX/Mac issue, not a Python/Tkinter one. – martineau Aug 26 '17 at 16:37
  • Thank you for the answers. I can see that it is a mac issue :) – Anders Aug 26 '17 at 17:34
  • How do you run the program? – skrx Aug 26 '17 at 17:56
  • This code works fine for me on my Mac. – Bryan Oakley Aug 26 '17 at 18:37
  • I use PyCharm, but I have also tried in the terminal to run it like `python script.py`, and to add `#!/usr/bin/env python` in the beginning of the script and then in the terminal `./script.py`. But I still have the same problem with both of these methods, that the popup freezes when I click on te "Yes" button. – Anders Aug 27 '17 at 06:34

0 Answers0