Here is the script for exit from the loop when any key is pressed. It is loop. Don’t try to put this is in while loop. It will make a infinite loop structure.
If your machine has python2.x use import Tkinter as tk. If your machine has python3.x use import tkinter as tk. This script is common for both.
try: import tkinter as tk except: import Tkinter as tk def main_fn(): root = tk.Tk() root.bind("<Key>", key) root.geometry('1x1+9000+9000') root.mainloop() def key(event): exit() main_fn()
I feel that it may help you lot.