0

I've been experiencing trouble with "quit" command in my Python (3.4.3, Windows 64 bits) and currently isn't working at all. It always fail and, whenever I try to use it along with tkinter module, my code freezes, my Python crashes and I have to restart the shell. Look at this simple example... Could anybody tell what is wrong with this?

from tkinter import *
top = Tk()
quit_button = Button(top, text='Quit', command=quit).pack()
mainloop()
cortmore
  • 19
  • 3
  • Does a window even pop up? Right now, nothing should – Zizouz212 Jul 01 '15 at 00:44
  • Your code works fine. I tested it on linux though. What error message are you getting (if any). – Marcin Jul 01 '15 at 02:04
  • @Zizouz212 Why the window should not pop up? – Marcin Jul 01 '15 at 02:06
  • 2
    Apply quit to the main window, command=top.quit in your example. Also, quit_button equals None because pack() returns None/nothing. –  Jul 01 '15 at 03:10
  • Zizouz212: No window pops up. Just the freezing/crashing effect. – cortmore Jul 01 '15 at 15:16
  • Marcin: That's interesting, because I suspect this could be a king of bug related to Windows or to the Windows version of Python or to 64 bits Python. – cortmore Jul 01 '15 at 15:19
  • Zizou212: The tkinter window does pop up, of course. The problem occurs only after you press the "Quit" button or any event involving a quit command. However, in some cases the traceback says something about a "raise a SystemExit"... – cortmore Jul 01 '15 at 15:25
  • Curly Joe: I've been trying to research in Tkinter manuals and tutorials and all of them show examples of "quit" command applied to buttons, frames or widgets different to top level window... So, "quit" shoul work even in the example I showed you and if it doesn't it means there's something else going wrong here... – cortmore Jul 01 '15 at 15:29
  • This code works fine for me so it may be your installation. You should always connect to specific containers, so use command=top.quit and change the last line to top.mainloop() as quit, mainloop, etc. are all functions in the Tk() class / namespace. –  Jul 01 '15 at 17:06

2 Answers2

0

Just tested your code, and I am having the same issue. The quit command should be top.quit, but that didn't work either. However, command=top.destroy worked fine for me, so if that is acceptable for you situation, try that out.

Sam Krygsheld
  • 2,060
  • 1
  • 11
  • 18
  • Thanks, Sam Krygsheld. It's interesting that you experience the same issue. "Destroy" command works fine for me, too. But I'm curious about "quit", because I suspect it could be a Windows bug or something like that. – cortmore Jul 01 '15 at 15:14
  • There's something else: if I import sys and try to use sys.exit it fails too. Are these issues related? Do you experience the same? – cortmore Jul 01 '15 at 15:50
  • I've never run into this before on my own, but yes, it looks like sys.exit has virtually the same effect as top.quit for me. – Sam Krygsheld Jul 02 '15 at 17:14
0

You had to write command=top.quit, not just command=quit. There is your mistake.

Guseyn013
  • 63
  • 9