I am using IDLE (Python 3.6 64-bit). Currently, I am using Tkinter to create a GUI. I have a button in my code that is supposed to terminate the program. As of now, it only closes out the "tk" root window (using root.destroy()
). I want it to also close out the shell and go back to where I can edit the code (i.e. back to my IDLE). How can I do this?
Asked
Active
Viewed 660 times
0
-
Try this: http://stackoverflow.com/questions/73663/terminating-a-python-script – Lou Franco Mar 14 '17 at 19:31
-
@LouFranco That question is about killing the process running the program (`raise SystemExit` and equivalents. SteMod is asking about killing something in another process (the Shell in the IDLE process), though doing so is not necessary to continue editing. – Terry Jan Reedy Mar 16 '17 at 22:31
-
Well I know it's not necessary, but I would just like to do it anyhow. – SteMob Mar 17 '17 at 12:51
1 Answers
0
When you run code from an IDLE editor window, any existing program run from IDLE is terminated. Unless your code somehow grabs control of the mouse, you should always be able to click on any editor window or its taskbar icon (on Windows) and start editing some more. Example: run the following from an IDLE editor.
import tkinter as tk
root = tk.Tk()
#root.destroy()
A tk window is dispayed. Click on the editor window, remove the '#', and run again. The first tk window disappears and a >>>
prompt appears in the Shell window.
A python program run from IDLE, cannot* close its parent IDLE, anymore than a python program run in a console can close the parent console.
- I am excluding things like, on *nix, getting the parent process number and issuing a 'kill ' command.

Terry Jan Reedy
- 18,414
- 3
- 40
- 52