I’ve just started working with wxPython, using both the book and the
website, and I’m getting some crashes with really basic code. I’ve
given details below; please let me know if there’s any other info
that’s relevant.
Thanks in advance for your help!
–Mike
Problem description: Python crashes when showing a simple window
Steps to reproduce: enter the code below either in the interpreter or
in a file and run it:
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)
app.MainLoop()
(Taken from http://wiki.wxpython.org/Getting%20Started#head-6e8427493dcc765fb873a1838adfbd6b8d08e0ee)
The crash happens when the wxPython window is given focus, bringing
down python.exe. It can also happen without the last call, during
frame.Show(), if the window is moved or its shape is changed.
Sometimes this will run okay the first time through in PythonWin.
However trying to run it again (even after closing the script file and
reopening it) gives the following error before eventually crashing
PythonWin:
Traceback (most recent call last):
File "C:\Python26\Lib\SITE-P~1\
PYTHON~1\pywin\framework\scriptutils.py",
line 312, in RunScript
exec codeObject in __main__.__dict__
File “C:\Users\Mike\Documents\Programming\wxPython\test.py”, line 3,
in
frame = wx.Frame(None, wx.ID_ANY, "Hello World")
File “C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx_windows.py”,
line 505, in init
_windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
PyNoAppError: The wx.App object must be created first!
Environment
···
OS: Vista Home Premium, with all updates
Python distribution: ActiveState Python 2.6.1.1 (Python 2.6.1)
wxPython version: 2.8.9.2 for Python 2.6, from win32-unicode binary
from http://www.wxpython.org/download.php
wxPython installation directory: C:\Python26\Lib\site-packages (default)
PYTHONPATH: C:\Python26;C:\Python26\Lib;C:\Python26\Lib\site-packages;C:\Python26\Lib\site-packages\django;C:\Python26\Lib\site-packages\django\bin;C:\Python26\Lib\site-packages\django*
(My PYTHONPATH has all this extra stuff because pointing it to the site-packages directory wasn’t sufficient for running django, for some reason.)