Question on importing wxPython

Mike Driscoll kyosohma at gmail.com
Mon Jan 28 13:42:02 EST 2008


On Jan 28, 12:06 pm, "Steven W. Orr" <ste... at syslang.net> wrote:
> python-2.3.5
> wx-2.6
>
> I just bought the wxPython In Action book and I see that all the examples
> say to
> import wx
> All of our pre-existing code was horribly doing a
> from wxPython import *
>
> I changed all the code so that it was doing an import wx and found that
> everything was broken. In particular, references to wxNewId would fail.
>
> 634 > python
> Python 2.3.5 (#2, May  4 2005, 08:51:39)
> [GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> import wx
> >>> wx.wxNewId
>
> Traceback (most recent call last):
>    File "<stdin>", line 1, in ?
> AttributeError: 'module' object has no attribute 'wxNewId'
>
>
>
> In fact, the *only* way to get it was to go back to
> import wxPython
> and then refer to it as wxPython.wx.wxNewId
>
> Is my system broken or am I missing something? i.e., should I be able to
> say import wx?
>
> TIA
>
> --
> Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
> happened but none stranger than this. Does your driver's license say Organ ..0
> Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
> individuals! What if this weren't a hypothetical question?
> steveo at syslang.net

I think the issue is that you are using the old style of wxPython. The
new style is wx.Something, so in this case, you want wx.NewId(). See
sample code below:

import wx
new_id = wx.NewId()

This helps the developer know what library that function comes from. I
see you are using 2.6. Just so you know, 2.8 is out now...you may want
to upgrade. Also, there's a really nice wxPython community mailing
list you can join, which you'll find here: http://wxpython.org/maillist.php

Mike




More information about the Python-list mailing list