wx: PyNoAppError

Discussion in 'Python' started by SuperHik, May 31, 2006.

  1. SuperHik

    SuperHik Guest

    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?
    SuperHik, May 31, 2006
    #1
    1. Advertising

  2. 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
    Scott David Daniels, May 31, 2006
    #2
    1. Advertising

  3. SuperHik

    SuperHik Guest

    Scott David Daniels wrote:
    > 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!

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

    I wasn't running them simultaneously. I ended the first (and only) one
    and then tried to start it again.
    >
    > --Scott David Daniels
    >
    SuperHik, May 31, 2006
    #3
  4. SuperHik

    gblandst

    Joined:
    Oct 14, 2006
    Messages:
    2
    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]
    
    gblandst, Oct 14, 2006
    #4
  5. SuperHik

    cosmo25

    Joined:
    Mar 17, 2011
    Messages:
    1
    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.""
    cosmo25, Mar 17, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page