在Mac OS上运行python代码时出错
我儿子刚在学校开始学习python,他必须在Mac OS上编写一个简单的程序 代码是这样的在Mac OS上运行python代码时出错,python,Python,我儿子刚在学校开始学习python,他必须在Mac OS上编写一个简单的程序 代码是这样的 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_RETRY
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)
执行此代码时,将显示以下消息
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'
回溯(最近一次呼叫最后一次):
文件“/Users/KeeganBarretto/Documents/messagebox 5.py”,第25行,在
结果=mBox(无,“你知道你在做什么吗?”,“支持”,图标|惊叹| MB |帮助)
文件“/Users/KeeganBarretto/Documents/messagebox 5.py”,第5行,mBox格式
return(ctypes.windl.user32.MessageBoxW(模式、消息、标题、样式))
AttributeError:模块“ctypes”没有属性“windell”
有人能帮他解决这个问题吗。正如我提到的,他是python新手,学习python是他计算机学习的一部分。该代码只在Windows上工作,因为它从Windows
user32.dll调用MessageBoxW
windell
是用于Windows的,而不是Unix。有其他方法吗?用macOS替代消息框调用吗(例如,快速搜索)或在Windows上运行此功能。