Is it possible to let a python program execute only if a wrong password is given at the login screen of my raspberry pi?
Have a look at libpam-script. It allows you to execute scripts during authorization, password changes and sessions.
To meet your need, you can build a PAM configuration (in
/etc/pam.d/<whatever>) that arranges for this module to execute right before
pam_deny only if the normal sequence of modules denies the login.