0

I have a small tkinter gui that generates some reports. I built a quit button into it. The button works perfectly when I launch the script, but I converted it to an exe with cx_freeze and the entire program is working except the quit button.

def quits():
    quit()

I created the quit button to call this quits function because I read that just calling quit directly could cause problems. Anyone have any idea why this is not working as an exe?

Joe
  • 2,641
  • 5
  • 22
  • 43
  • 1
    You should `import sys; sys.exit(0)` instead. – a_guest Jun 27 '17 at 18:33
  • 1
    quit() is an interpreter function, not a Python language function. It exits the interpreter. Since you're running a C program, there is no interpreter to exit. Are you getting an error or is the button just not doing anything? In any case, I found this thread: https://stackoverflow.com/questions/73663/terminating-a-python-script. Use sys.exit() or os._exit() instead to kill a thread or an entire program at the C level – Alan Leuthard Jun 27 '17 at 18:34
  • Please read the documentation of [`quit`](https://docs.python.org/3/library/constants.html#quit): "[...] useful for the interactive interpreter shell and should not be used in programs". – Matthias Jun 27 '17 at 18:34
  • 1
    I believe [this link](https://stackoverflow.com/a/19747562/7073884) will provide more than enough information. – Luke Jun 27 '17 at 18:36
  • Thanks for the help guys I will look into the sys functions. I am not getting any errors. Still pretty new to this so no errors makes it hard to troubleshoot – Joe Jun 27 '17 at 18:36

1 Answers1

1

As per the comments the quit function doesn't work outside of the interpreter

def quits():
    sys.exit()

That does the trick

Joe
  • 2,641
  • 5
  • 22
  • 43