how to create a keylogger using a python????

This will do it ...

# tk_KeyLogger.py
# show a character key when pressed

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def key(event):
    """show just the character key"""
    if event.keysym == 'Escape':
        root.destroy()
    print(event.char)

root = tk.Tk()
print("Press a key (Escape key to exit): ")
root.bind_all('<Key>', key)
# don't show the tk window
root.withdraw()
root.mainloop()