Search code examples
pythonstringwxpython

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.

# some code
MessageBox = ctypes.windll.user32.MessageBoxA
# some other code
testString = self.statusBar1.GetStatusText(0)
# displays "azertyu"
MessageBox(None, "azertyu", 'COUCOU', 0)
# displays 'M'
MessageBox(None, testString, 'COUCOU3', 0)
# displays 'a'
MessageBox(None, testString[1:], 'COUCOU3', 0) #
#displays 'c'
MessageBox(None, testString[2:], 'COUCOU3', 0)

The full string is 'Machine' (it's actually longer than that). How comes Python considers any character is the ending one and displays only one character at once ? Am I missing some Python basics here ?

PS. GetStatusText reference is available at http://www.wxpython.org/docs/api/wx.StatusBar-class.html#GetStatusText. I have tested GetStatusText with a very long string and it doesn't seem to cut texts.


Solution

  • 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.