Need some help with ctypes library.
According to this link I can create a messagebox using the following code:
import ctypes # An included library with Python install.
ctypes.windll.user32.MessageBoxA(0, "Your text", "Your title", 1)
And configure the last parameter to define the type of messagebox:
## Styles:
## 0 : OK
## 1 : OK | Cancel
## 2 : Abort | Retry | Ignore
## 3 : Yes | No | Cancel
## 4 : Yes | No
## 5 : Retry | No
## 6 : Cancel | Try Again | Continue
How can I create a conditional statement using the pressed button inside my
ctypes.windll.user32.MessageBoxA
?
def close_program(self, event):
ctypes.windll.user32.MessageBoxA(0, "Are you sure?", "Alert!", 4)
if response == "Yes":
sys.exit(0)
else:
pass
I've already tried this code, unsuccessfully:
def close_program(self, event):
if ctypes.windll.user32.MessageBoxA(0, "Are you sure?", "Alert!", 4) == "Yes":
sys.exit(0)
else:
pass
EDIT:
Got a solution by looking at the provided link here.
def close_program(self, evt):
# ctypes messagebox return values
MB_OK = 0
MB_OKCANCEL = 1
MB_YESNOCANCEL = 3
MB_YESNO = 4
IDOK = 0
IDCANCEL = 2
IDABORT = 3
IDYES = 6
IDNO = 7
resp = ctypes.windll.user32.MessageBoxA(0, "Are you sure?", "Alert!", 4)
if resp == IDYES:
sys.exit(0)
else:
pass