wx: PyNoAppError

S

SuperHik

Hi!

Using XP SP2, PythonWin 2.4.3, any trying to use wx 2.6.3.2
When using wx, the first time I run a script it runs fine.
Second time, it rasises an error:

[Script]**********************************
import wx
app = wx.App()
win = wx.Frame(None, title="Simple Editor")
win.Show()
app.MainLoop()

[Error]***********************************
Traceback (most recent call last):
File
"C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Python24\mystuff\ool.pyw", line 3, in ?
win = wx.Frame(None, title="Simple Editor")
File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_windows.py",
line 493, in __init__
newobj = _windows_.new_Frame(*args, **kwargs)
PyNoAppError: The wx.App object must be created first!
******************************************

So this happens no matter what the script is.
And it always occurs on the first line a new widget is created.
This is not a problem with the script, because it does the same
thing on every script I copied from the internet. It must be a
wx bug, but has anyone fixed it?
I googled and only found this:

http://mail.python.org/pipermail/tutor/2005-September/041678.html
*Not helpful
http://www.dogmelon.com.au/nsforum/viewtopic.php?p=5032&sid=53d6cc27c33f96f405873e044425e64c#5032
*Says that runnig the script outside of IDLE fixes the problem.
That works for me too but if there is a way to run it from IDLE
that would be much easier.

Any experience on this?
 
S

Scott David Daniels

SuperHik wrote:

(1) A wxPython question. Better to ask on the wxPython newsgroup
(listed as comp.python.wxpython on gmane).
Using XP SP2, PythonWin 2.4.3, any trying to use wx 2.6.3.2
When using wx, the first time I run a script it runs fine.
Second time, it rasises an error: ....
Up here you should have mentioned you are doing this in IDLE, that is
your problem.

Later in your message you say:
... *Says that runnig the script outside of IDLE fixes the problem.
That works for me too but if there is a way to run it from IDLE
that would be much easier.

This is the inevitable result of running a pair of GUIs simultaneously:
They both want control of the main program to run their idle loop, and
only can win.

--Scott David Daniels
(e-mail address removed)
 
S

SuperHik

Scott said:
SuperHik wrote:

(1) A wxPython question. Better to ask on the wxPython newsgroup
(listed as comp.python.wxpython on gmane).
I'm aware it's a wxPython question but I wasn't aware
of the group you mentioned. Thank you!
Up here you should have mentioned you are doing this in IDLE, that is
your problem.

Later in your message you say:

This is the inevitable result of running a pair of GUIs simultaneously:
They both want control of the main program to run their idle loop, and
only can win.
I wasn't running them simultaneously. I ended the first (and only) one
and then tried to start it again.
 
Joined
Oct 14, 2006
Messages
2
Reaction score
0
There is actually a simple fix to this. The problem arises because the wx.App object already exists the second time you try to run the program from within IDLE (or whatever IDE you may be using). Deleting it each time the program terminates will prevent an exception.

Here's an example of the fix applied to a "Hello, world!" program. Text in red represents changes.

Code:
import wx

class frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        panel = wx.Panel(self)
        wx.StaticText(panel, label="Hello, world!")
        self.Show()
        
app = wx.App()

[COLOR="Red"]try:[/COLOR]
    frame()
    app.MainLoop()
[COLOR="Red"]finally:[/COLOR]
[COLOR="Red"]    del app[/COLOR]
 
Joined
Mar 17, 2011
Messages
1
Reaction score
0
app Error

Thank you for your solution to this problem, my program will now run, however if I click on the background Python Shell it comes up with this error and closes:

""Microsoft Visual C++ Runtime Library
Runtime Error!
Program: D:\Python2.5\pythonw.exe

This program has requested the Runtime to terminate it in an unusual way.""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top