Like Rawing said, you can use the keyboard library, for example:
import keyboard
keyboard.add_hotkey('a', lambda: print "a was pressed")
Note that for this to work, the keyboard library must be installed, you can do this with $ sudo pip install keyboard
Edit: You might have to use $ sudo python -m pip install keyboard
Edit: Or you might have to use $ sudo py -m pip install keyboard
Edit: Or even $ sudo -H pip install keyboard
Also, note that I'm assuming you're using python 2.7.
Edit: if you wonder why I assumed you were using python 2.7 it was because you used from Tkinter import *
in your GUI example, and in python 2.7, the tkinter module is called "Tkinter", whilst in python 3.6, tkinter is called "tkinter" so in python 3 you should use from tkinter import *
(Note the lowercase "t" versus the capital "T" in tkinter/Tkinter)
Also, note that the keyboard module doesn't work on Mac (at least their pip page only says they support Windows and Linux, but it might work if you have luck)
Lastly, note that I haven't tried this myself since I currently do not have access to a computer with python installed. If it doesn't work, comment me and I'll try to find another solution :)
Edit: @RezaSaadati approved that it worked.