Вопрос

I have written a simple python program in version 2.7.6 (32 bit). But when i display any message in a message box it comes in some weird language. The code is below

import Tkinter as tk
import win32com.client
import pythoncom
import ctypes
import sys
import glob
import sys
import os

MessageBox = ctypes.windll.user32.MessageBoxW 

if __name__ == "__main__":
   MessageBox(None, "Hello", 'Window title',0)

and this is the output

error output

Это было полезно?

Решение

You need to send a unicode string; because you are using the unicode version of message box MessageBoxW, if you want to send normal ascii strings you need to use MessgeBoxA

ctypes.windll.user32.MessageBoxA(None, 'Hello', 'Window title', 0) # or
ctypes.windll.user32.MessageBoxW(None, u'Hello', u'Window title', 0)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top