Search code examples
pythontkinterstackwindow

How do I bring a kill window to the front in tkinter?


I have a python program that opens up in full screen. In the program window is a button that the user is supposed to use when they want to exit the program. This is the function for when they click the button:

def closeProgram():
    file_name = os.path.basename(sys.argv[0])
    file = open("SaveFile1.txt", "a")
    file.write(file_name)
    file.close()
    exit()

But when I call the exit() function, the kill window that pops up, asking if I REALLY want to stop the program, shows up underneath the program window. Is there way a to bring the kill window to the front?


Solution

  • This is caused by IDLE, not by python or tkinter. Use raise SystemExit instead to kill only your program and not IDLE. Or (much better) redesign your program so that it reaches the end when done. If you are using a tkinter mainloop you can use root.quit() to end it.