0

My son has just started learning python in school and he has to write a simple program on Mac OS.

the code is this

import ctypes


def mBox(mode, message, title, style):
    return(ctypes.windll.user32.MessageBoxW(mode, message, title, style))

MB_OK = 0
MB_OKCANCEL = 1
MB_ABORTRETRYIGNORE = 2
MB_YESNOCXL = 3
MB_RETRYNO = 5
MB_CANCELTRYAGAINCONTINUE = 6
MB_HELP = 16384
ICON_EXCLAIM = 48
ICON_INFO = 64
ICON_STOP = 16

IDOK = 0
IDCANCEL = 2
IDABORT = 3
IDYES = 6
IDNO = 7


result = mBox(None, "Do you know what you are doing?","Support",ICON_EXCLAIM | MB_HELP)


if result == IDYES:
    print("user pressed Yes")
elif result == IDNO:
    print("user pressed No")
elif result == IDCANCEL:
    print("user pressed Cancel")
else:
    print("unknown return code",result)

When this code is executed the following message is displayed

Traceback (most recent call last):
  File "/Users/KeeganBarretto/Documents/MESSAGE BOXES 5.py", line 25, in <module>
    result = mBox(None, "Do you know what you are doing?","Support",ICON_EXCLAIM | MB_HELP)
  File "/Users/KeeganBarretto/Documents/MESSAGE BOXES 5.py", line 5, in mBox
    return(ctypes.windll.user32.MessageBoxW(mode, message, title, style))
AttributeError: module 'ctypes' has no attribute 'windll'

Can someone help him in resolving this issue. As I mentioned he is new to python and learning as part of his computer studies.

1
  • 1
    windll is for Windows, not Unix. Commented Apr 28, 2020 at 18:44

1 Answer 1

2

That code only works on Windows, since it's calling MessageBoxW from the Windows user32.dll.

Sign up to request clarification or add additional context in comments.

2 Comments

is there any alternative ?
Replacing the message box call with a macOS alternative (quick search gives e.g. stackoverflow.com/questions/50497479/…), or running this on Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.