Why does wx.Colour(5,5,5).Get() return a tuple, but wx.RED.Get() raise a type error?

What is going on here?

import wx
type(wx.Colour(5,5,5))
<class ‘wx._gdi.Colour’>
type(wx.RED)
<class ‘wx._gdi.Colour’>
wx.Colour(5,5,5).Get()
(5, 5, 5)
wx.RED.Get()
Traceback (most recent call last):
File “C:\Program Files (x86)\Wing IDE 5.0\src\debug\tserver_sandbox.py”, line 1, in

# Used internally for debug sandbox under external interpreter

File “C:\Python27\Lib\site-packages\wx-2.9.4-msw\wx_gdi.py”, line 266, in Get
return gdi.Colour_Get(*args, **kwargs)
TypeError: in method ‘Colour_Get’, expected argument 1 of type ‘wxColour *’

Found an answer. Apparently I have to do:

app = wx.App(0)

first, though I don’t know why. After the app is instantiated, I can do:

wx.RED.Get()
and I get
(255, 0, 0)

Arrgh.

···

On Friday, December 20, 2013 5:11:35 PM UTC-5, Rufus wrote:

What is going on here?

import wx
type(wx.Colour(5,5,5))
<class ‘wx._gdi.Colour’>
type(wx.RED)
<class ‘wx._gdi.Colour’>
wx.Colour(5,5,5).Get()
(5, 5, 5)
wx.RED.Get()
Traceback (most recent call last):
File “C:\Program Files (x86)\Wing IDE 5.0\src\debug\tserver_sandbox.py”, line 1, in

# Used internally for debug sandbox under external interpreter

File “C:\Python27\Lib\site-packages\wx-2.9.4-msw\wx_gdi.py”, line 266, in Get
return gdi.Colour_Get(*args, **kwargs)
TypeError: in method ‘Colour_Get’, expected argument 1 of type ‘wxColour *’

Rufus wrote:

What is going on here?

>>> import wx
>>> type(wx.Colour(5,5,5))
<class 'wx._gdi.Colour'>
>>> type(wx.RED)
<class 'wx._gdi.Colour'>
>>> wx.Colour(5,5,5).Get()
(5, 5, 5)
>>> wx.RED.Get()
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE
5.0\src\debug\tserver\_sandbox.py", line 1, in <module>
# Used internally for debug sandbox under external interpreter
File "C:\Python27\Lib\site-packages\wx-2.9.4-msw\wx\_gdi.py", line 266,
in Get
return _gdi_.Colour_Get(*args, **kwargs)
TypeError: in method 'Colour_Get', expected argument 1 of type 'wxColour *'

Because wx.RED is just a placeholder object to start with and the real color instance is not created until after a wx.App instance has been created.

  >>> wx.RED.Get()
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "wx/_gdi.py", line 266, in Get
      return _gdi_.Colour_Get(*args, **kwargs)
  TypeError: in method 'Colour_Get', expected argument 1 of type 'wxColour *'
  >>> app = wx.App()
  >>> wx.RED.Get()
  (255, 0, 0)

···

--
Robin Dunn
Software Craftsman