PyApp does not create wxApp instance

I have built wxPython 4 for Python3 using the source tarball on OpenSuse Leap

It builds and installs

From the python3 console (from Eric IDE) if I type

import wx
app = wx.PyApp
frame=wx.Frame(None,wx.ID_ANY,“Test”)

I get after the 3rd line:

Traceback (innermost last):
File “”, line 1, in
wx._core.PyNoAppError: The wx.App object must be created first!

What am I doing wrong?

If I use wxPython3 it works.

Regards

Bazza

I think the second line should be

app = wx.PyApp()

(parentheses missing in the original).

Adrian

···

On Monday, January 29, 2018 at 1:20:56 AM UTC-7, Bazza Hill wrote:

I have built wxPython 4 for Python3 using the source tarball on OpenSuse Leap

It builds and installs

From the python3 console (from Eric IDE) if I type

import wx
app = wx.PyApp
frame=wx.Frame(None,wx.ID_ANY,“Test”)

I get after the 3rd line:

Traceback (innermost last):
File “”, line 1, in
wx._core.PyNoAppError: The wx.App object must be created first!

What am I doing wrong?

If I use wxPython3 it works.

Regards

Bazza

Thanks,

However the brackets make no difference. The code (such as it is) runs using wxPython 3 (PyApp changed to App). I can show the problem is related to the way the wxApp is created. By creating the wxApp instance before invoking the python interpreter “it works”.

I am minded to give up until wxPython 4 is stable.

Bazza

···

On Monday, 29 January 2018 17:09:31 UTC, Adrian Hill wrote:

I think the second line should be

app = wx.PyApp()

(parentheses missing in the original).

Adrian

On Monday, January 29, 2018 at 1:20:56 AM UTC-7, Bazza Hill wrote:

I have built wxPython 4 for Python3 using the source tarball on OpenSuse Leap

It builds and installs

From the python3 console (from Eric IDE) if I type

import wx
app = wx.PyApp
frame=wx.Frame(None,wx.ID_ANY,“Test”)

I get after the 3rd line:

Traceback (innermost last):
File “”, line 1, in
wx._core.PyNoAppError: The wx.App object must be created first!

What am I doing wrong?

If I use wxPython3 it works.

Regards

Bazza

Thanks,

However the brackets make no difference. The code (such as it is) runs
using wxPython 3 (PyApp changed to App). I can show the problem is
related to the way the wxApp is created. By creating the wxApp instance
before invoking the python interpreter "it works".

I am minded to give up until wxPython 4 is stable.

Bazza

Testing this on Window 10:
> ipython
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32
bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: import wx

In [2]: pa = wx.PyApp

In [3]: pa.IsDisplayAvailable()
Out[3]: True

In [4]: frame=wx.Frame(None,wx.ID_ANY,"Test")

···

On 29/01/2018 18:13, Bazza Hill wrote:
---------------------------------------------------------------------------
PyNoAppError Traceback (most recent call last)
<ipython-input-4-bff7e941f974> in <module>()
----> 1 frame=wx.Frame(None,wx.ID_ANY,"Test")

PyNoAppError: The wx.App object must be created first!

In [5]: app = wx.App()

In [6]: frame=wx.Frame(None,wx.ID_ANY,"Test")

In [7]: del frame

In [8]: exit

Steve-Gadget@MOON C:\Users\Steve-Gadget
> ipython
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32
bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: import wx

In [2]: pa = wx.PyApp()

In [3]: frame=wx.Frame(None,wx.ID_ANY,"Test")

In [4]: exit

Steve-Gadget@MOON C:\Users\Steve-Gadget
> c:\Python36_64\Scripts\ipython.exe
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit
(AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import wx

In [2]: pa = wx.PyApp()

In [3]: frame=wx.Frame(None,wx.ID_ANY,"Test")

In [4]: exit
Steve-Gadget@MOON C:\Users\Steve-Gadget
> c:\Python36_64\python -c "import wx;print(wx.version());"
4.0.0b2 msw (phoenix)

Steve-Gadget@MOON C:\Users\Steve-Gadget
> python -c "import wx;print(wx.version());"
4.0.0b1 msw (phoenix)

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

Bazza Hill wrote:

However the brackets make no difference. The code (such as it is) runs
using wxPython 3 (PyApp changed to App). I can show the problem is
related to the way the wxApp is created. By creating the wxApp
instance before invoking the python interpreter "it works".

What does that mean? Are you blending wxPython and wxWidgets C++ code
here? Are you saying you can create a wxApp in C++ code before
launching Python and it works, but if you create a wx.App in the Python
code, it does not?

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Tim,
Thanks.

I am starting with wxPython 4 built from sources.

If I try this at the python 3 console:
import wx
app = wx.PyApp()
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)
app.MainLoop()

It fails at “frame = wx.Frame(None, wx.ID_ANY, “Hello World”)” because there is no wxApp instance.

If I write a simple wxWidgets application that invokes the python interpreter after creating a wxApp instance and run:

import wx
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)

The frame shows.

Bazza

···

On Monday, 29 January 2018 19:18:36 UTC, Tim Roberts wrote:

Bazza Hill wrote:

However the brackets make no difference. The code (such as it is) runs

using wxPython 3 (PyApp changed to App). I can show the problem is

related to the way the wxApp is created. By creating the wxApp

instance before invoking the python interpreter “it works”.

What does that mean? Are you blending wxPython and wxWidgets C++ code

here? Are you saying you can create a wxApp in C++ code before

launching Python and it works, but if you create a wx.App in the Python

code, it does not?


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

wx.PyApp is an implementation detail and should not be used directly. Instead you should always use wx.App. All of the bootstrapping code needed to use wxWidgets from Python happens in wx.App.

···

Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)

[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

Type “help”, “copyright”, “credits” or “license” for more information.

import wx

wx.version()

‘4.0.0 osx-cocoa (phoenix)’

app = wx.App()

frm = wx.Frame(None, title=‘Hello’)

frm.Show()

True

app.MainLoop()

0

Robin Dunn

Software Craftsman

On Monday, January 29, 2018 at 11:29:09 PM UTC-8, Bazza Hill wrote:

Tim,
Thanks.

I am starting with wxPython 4 built from sources.

If I try this at the python 3 console:
import wx
app = wx.PyApp()
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)
app.MainLoop()

It fails at “frame = wx.Frame(None, wx.ID_ANY, “Hello World”)” because there is no wxApp instance.

If I write a simple wxWidgets application that invokes the python interpreter after creating a wxApp instance and run:

import wx
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)

The frame shows.

Bazza

On Monday, 29 January 2018 19:18:36 UTC, Tim Roberts wrote:

Bazza Hill wrote:

However the brackets make no difference. The code (such as it is) runs

using wxPython 3 (PyApp changed to App). I can show the problem is

related to the way the wxApp is created. By creating the wxApp

instance before invoking the python interpreter “it works”.

What does that mean? Are you blending wxPython and wxWidgets C++ code

here? Are you saying you can create a wxApp in C++ code before

launching Python and it works, but if you create a wx.App in the Python

code, it does not?


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Thanks.

That makes sense. Elsewhere it said you should use PyApp and not App.

There are other problems i_wxPyCheckForApp should check for wxAppConsole::GetInstance() being non-null, not wxTheApp. This is because the python interpreter might embedded in an application with its own wxApp.

Really the wxApp interface should be in a separate module optionally imported. I have done this and it works well both embedded and non-embedded python.

Bazza

···

On Tuesday, 30 January 2018 22:12:18 UTC, Robin Dunn wrote:

wx.PyApp is an implementation detail and should not be used directly. Instead you should always use wx.App. All of the bootstrapping code needed to use wxWidgets from Python happens in wx.App.

Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)

[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

Type “help”, “copyright”, “credits” or “license” for more information.

import wx

wx.version()

‘4.0.0 osx-cocoa (phoenix)’

app = wx.App()

frm = wx.Frame(None, title=‘Hello’)

frm.Show()

True

app.MainLoop()

0

Robin Dunn

Software Craftsman

http://wxPython.org

On Monday, January 29, 2018 at 11:29:09 PM UTC-8, Bazza Hill wrote:

Tim,
Thanks.

I am starting with wxPython 4 built from sources.

If I try this at the python 3 console:
import wx
app = wx.PyApp()
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)
app.MainLoop()

It fails at “frame = wx.Frame(None, wx.ID_ANY, “Hello World”)” because there is no wxApp instance.

If I write a simple wxWidgets application that invokes the python interpreter after creating a wxApp instance and run:

import wx
frame = wx.Frame(None, wx.ID_ANY, “Hello World”)
frame.Show(True)

The frame shows.

Bazza

On Monday, 29 January 2018 19:18:36 UTC, Tim Roberts wrote:

Bazza Hill wrote:

However the brackets make no difference. The code (such as it is) runs

using wxPython 3 (PyApp changed to App). I can show the problem is

related to the way the wxApp is created. By creating the wxApp

instance before invoking the python interpreter “it works”.

What does that mean? Are you blending wxPython and wxWidgets C++ code

here? Are you saying you can create a wxApp in C++ code before

launching Python and it works, but if you create a wx.App in the Python

code, it does not?


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Thanks.

That makes sense. Elsewhere it said you should use PyApp and not App.

Where did you see that?

There are other problems i_wxPyCheckForApp should check for wxAppConsole::GetInstance() being non-null, not wxTheApp. This is because the python interpreter might embedded in an application with its own wxApp.

···

On Tuesday, January 30, 2018 at 8:49:31 PM UTC-8, Bazza Hill wrote:

Robin Dunn

Software Craftsman

Robin,

I found the recommendation to use wx.PyApp and not wx.App in a search, along the lines of wx.App does not work but wx.PyApp does.

···

On Wednesday, 31 January 2018 18:22:09 UTC, Robin Dunn wrote:

On Tuesday, January 30, 2018 at 8:49:31 PM UTC-8, Bazza Hill wrote:

Thanks.

That makes sense. Elsewhere it said you should use PyApp and not App.

Where did you see that?

There are other problems i_wxPyCheckForApp should check for wxAppConsole::GetInstance() being non-null, not wxTheApp. This is because the python interpreter might embedded in an application with its own wxApp.

https://github.com/wxWidgets/Phoenix/issues/720

Robin Dunn

Software Craftsman

http://wxPython.org