Python 3.x MessageBox仅显示一个字符

Python 3.x MessageBox仅显示一个字符,python-3.x,ctypes,Python 3.x,Ctypes,为什么在标题和方框内只打印一个字符。我如何确保它打印出所有内容 import ctypes ctypes.windll.user32.MessageBoxA(0, "info", "title", 3) 标题只打印“i”,只打印“t”,这是什么问题?如果您测试 ctypes.windll.user32.MessageBoxW(0, "info", "title", 3) ctypes.windll.user32.MessageBoxA(0, "info".encode('ascii'),

为什么在标题和方框内只打印一个字符。我如何确保它打印出所有内容

import ctypes 
ctypes.windll.user32.MessageBoxA(0, "info", "title", 3)
标题只打印“i”,只打印“t”,这是什么问题?

如果您测试

ctypes.windll.user32.MessageBoxW(0, "info", "title", 3)
ctypes.windll.user32.MessageBoxA(0, "info".encode('ascii'), 
                                 "title".encode('ascii'), 3)
应该有“信息”和“标题”。如果你测试

ctypes.windll.user32.MessageBoxW(0, "info", "title", 3)
ctypes.windll.user32.MessageBoxA(0, "info".encode('ascii'), 
                                 "title".encode('ascii'), 3)
所以这似乎是某种文本编码问题。默认情况下可能传递UTF-16-le编码的字符串

>>> 'info'.encode('utf-16-le')
b'i\x00n\x00f\x00o\x00'
>>> 'title'.encode('utf-16-le')
b't\x00i\x00t\x00l\x00e\x00'

由于
MessageBoxA
需要
NULL
终止的C字符串,因此只考虑开头的两个字符,即
'i\0'
't\0'

ctypes.windell.user32.MessageBoxA(0,b'info',b'title',3)
也可以