Skip to content Skip to sidebar Skip to footer

String Problems With Python

I am a Python noob so I may be missing something here, but I have a problem with how a string is handled inside my program. When I display it, only the first character is displayed

Solution 1:

MessageBoxA is the ascii version of the MessageBox win32 API. Your testString is probably a Unicode value, so the value being passed to MessageBoxA will end up looking like an array of bytes with a zero in every other index. In other words it looks like a character string with just one character terminated by a NULL character. I bet if you use str(testString) or switch to MessageBoxW then it will work as expected, however you really should be using wx.MessageBox or wx.MessageDialog instead.

Solution 2:

If you are using wxPython, why are you trying to show a message box with ctypes? The wxPython package has its own message dialogs. See the following links:

The wxPython demo package (downloadable from the wxPython website) has examples of MessageDialog and GenericMessageDialog.

Solution 3:

Try ctypes.windll.user32.MessageBoxW instead of ctypes.windll.user32.MessageBoxA:

import ctypes
ctypes.windll.user32.MessageBoxW(None, "Hello, world!", "Test", 0)

Solution 4:

It's treating the testString as a list

In [214]: for x in"Machine":
   .....:     print x
   .....:
M
a
c
h
i
n
e

Have you tried ?

MessageBox(None, [testString], 'COUCOU3', 0)

as it's as if MessageBox is expecting a list of txt, which might makes sense:

["DANGER", "Will Robinson"]

Would then give two lines of txt on your message.

PURE GUESSWORK

Post a Comment for "String Problems With Python"