tset0401
tset0401

Reputation: 25

exit python program without close Tkinter window

when I was working with Tkinter in python, I encountered an interesting problem that when I run a python program in Linux Terminal, my code opened a Tkinter widget like this:

root = Tk()
root.title("Hello World")
txt = Text(root, width=60, height=20, wrap="word")
txt.insert(INSERT, "HELLO WORLD")
txt.insert(END, "---------------END---------------")
txt.config(state=DISABLED)
txt.bind("<Leave>", close_when_lost_focus)
txt.pack()
root.mainloop()

and then I force quit python program with Ctrl + Z, the Tkinter window was still there and I couldn't close it until I closed the Terminal. Any body knows what happened?

Upvotes: 0

Views: 394

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

control-z doesn't force quit a program. It is more like putting it to sleep, or suspending it. You can cause the program to resume by typing the command fg (foreground) or bg (background).

fg brings it to the foreground, which makes it as if you never typed control-z.

bg places the job in the background and lets it continue running while allowing you to type additional commands in the terminal.

For more information see What is effect of CTRL + Z on a unix\Linux application

Upvotes: 1

Related Questions