473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

why "import wx" doesn't work?

I just learn to make a blank windows frame with python and wxpython. I found
the statment "import wx" cannot work as the original "from wxPython.wx
import *". I see in the readme file of wxpython that if I install it as the
default one, I can use "import wx" instead of the long one. What is wrong?
The code pasted below:

import wx # the default is "from wxPython.wx import *", I change it and it
just can't work.

class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, "Hello from wxPython")
frame.Show(true)
self.SetTopWindow(frame)
return true

app = MyApp(0)
app.MainLoop()
Jul 19 '05 #1
9 4946
monkey wrote:
I just learn to make a blank windows frame with python and wxpython. I found
the statment "import wx" cannot work as the original "from wxPython.wx
import *". I see in the readme file of wxpython that if I install it as the
default one, I can use "import wx" instead of the long one. What is wrong?
The code pasted below:

import wx # the default is "from wxPython.wx import *", I change it and it
just can't work.

class MyApp(wxApp):

....

Assuming you've installed a version of wxPython that is recent enough
that "import wx" works (it's really unclear from what you've written
above), then the problem you are facing is not using the namespace that
you've now imported. Do this instead:

class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(NULL, -1, "....
Note that "wx." before everything from wxPython...

-Peter
Jul 19 '05 #2
The Great 'monkey' uttered these words on 4/28/2005 2:09 PM:
I just learn to make a blank windows frame with python and wxpython. I found
the statment "import wx" cannot work as the original "from wxPython.wx
import *". I see in the readme file of wxpython that if I install it as the
default one, I can use "import wx" instead of the long one. What is wrong?
The code pasted below:

import wx # the default is "from wxPython.wx import *", I change it and it
just can't work.

Which version of wxPython are you running? What do you mean by "does not
work"...does the import fail or is your code giving errors?
Jul 19 '05 #3
It is the current version of wxPython(2.6). But follow you instruction it
still can't work...
But if using the default "from wxPython.wx import *", it work, don't know
what is the problem. May be this is an old example that cannot work with
"import wx". Because I get another example and it is ok.

Anyway, I hope I can catch up with you guys here in python programming soon.
Thanks a lot ( :
Assuming you've installed a version of wxPython that is recent enough
that "import wx" works (it's really unclear from what you've written
above), then the problem you are facing is not using the namespace that
you've now imported. Do this instead:

class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(NULL, -1, "....
Note that "wx." before everything from wxPython...

-Peter

Jul 19 '05 #4
> Which version of wxPython are you running? What do you mean by "does not
work"...does the import fail or is your code giving errors?


It is the current new version 2.6. The error message said that the class
wxApp is not defined...
But when using the default "from wxPython.wx import *", it works.
Jul 19 '05 #5
The Great 'monkey' uttered these words on 4/28/2005 5:30 PM:
It is the current version of wxPython(2.6). But follow you instruction it
still can't work...
But if using the default "from wxPython.wx import *", it work, don't know
what is the problem. May be this is an old example that cannot work with
"import wx". Because I get another example and it is ok.

I suspect you are mixing program code for the namespace version (import
wx) with the old method of importing (from wxPython.wx import *).

Here are two version of a very simple app... try both and see if you get
any errors. And if so, _please_ post the exact error you get.

--- BEGIN The "new" namespace version ----

import wx

class MainFrame(wx.Frame):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON _RESIZE):
wx.Frame.__init__(self, parent, id, title, size, pos, style)
self.Show(True)

app = wx.PySimpleApp()
frame = MainFrame(None, -1, "Test Wx NameSpace Style")
app.MainLoop()

--- END The "new" namespace version ----

--- BEGIN The old style import ----

from wxPython.wx import *

class MainFrame(wxFrame):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_R ESIZE):
wxFrame.__init__(self, parent, id, title, size, pos, style)
self.Show(True)

app = wxPySimpleApp()
frame = MainFrame(None, -1, "Test Wx Old Style")
app.MainLoop()

--- END The old style import ----

Hope that helped!

Thanks,
-Kartic

Jul 19 '05 #6
The Great 'monkey' uttered these words on 4/28/2005 5:50 PM:
Which version of wxPython are you running? What do you mean by "does not
work"...does the import fail or is your code giving errors?

It is the current new version 2.6. The error message said that the class
wxApp is not defined...
But when using the default "from wxPython.wx import *", it works.


See my previous post for examples... you are mixing the new import style
and old style of using the classes. That will not work.

Thanks,
-K
Jul 19 '05 #7

Użytkownik "monkey" <m@m.com> napisał w wiadomo¶ci
news:42**********@rain.i-cable.com...
Which version of wxPython are you running? What do you mean by
"does not
work"...does the import fail or is your code giving errors?


It is the current new version 2.6. The error message said that the
class
wxApp is not defined...


This is very good! wxApp is never defined if you use "import wx". You
must use "wx.wxApp" instead.

If you import a module using "import anything", then all the names
imported from the module must begin with "anything.". If you import wx
using "import wx", then ALL the wx commands, classes and variables
(all the names) MUST begin with 'wx.". Change them, and your program
will work.

"from wx import *" is a special shortcut, allowing you to use all the
names without "wx.". If you change "from something import *" to
"import something", your code will always break, this is normal.

regards,
Filip Dreger
Jul 19 '05 #8
They both work, thanks for your instruction ( :
I suspect you are mixing program code for the namespace version (import
wx) with the old method of importing (from wxPython.wx import *).

Here are two version of a very simple app... try both and see if you get
any errors. And if so, _please_ post the exact error you get.

--- BEGIN The "new" namespace version ----

import wx

class MainFrame(wx.Frame):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON _RESIZE):
wx.Frame.__init__(self, parent, id, title, size, pos, style)
self.Show(True)

app = wx.PySimpleApp()
frame = MainFrame(None, -1, "Test Wx NameSpace Style")
app.MainLoop()

--- END The "new" namespace version ----

--- BEGIN The old style import ----

from wxPython.wx import *

class MainFrame(wxFrame):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_R ESIZE):
wxFrame.__init__(self, parent, id, title, size, pos, style)
self.Show(True)

app = wxPySimpleApp()
frame = MainFrame(None, -1, "Test Wx Old Style")
app.MainLoop()

--- END The old style import ----

Hope that helped!

Thanks,
-Kartic

Jul 19 '05 #9
Bright ( ; You show me a crystal clear explaination.
As a newbie in python and even oop, I find the python documentation is not
easy to figure out. That's great with you guys so nice here.
This is very good! wxApp is never defined if you use "import wx". You
must use "wx.wxApp" instead.

If you import a module using "import anything", then all the names
imported from the module must begin with "anything.". If you import wx
using "import wx", then ALL the wx commands, classes and variables
(all the names) MUST begin with 'wx.". Change them, and your program
will work.

"from wx import *" is a special shortcut, allowing you to use all the
names without "wx.". If you change "from something import *" to
"import something", your code will always break, this is normal.

regards,
Filip Dreger

Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of...
0
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24...
2
by: wen | last post by:
i have written some code in test.py as below: import __main__ if __name__!='__main__': print 1 print 2 when i run test.py, i got 2 on the screen.
1
by: Xiao Jianfeng | last post by:
Hello, In pymol I can use "from chempy import Atom" but "import chempy.Atom" doesn't work. It says,"ImportError: No module named Atom". What is going wrong ? Thanks
3
by: Mudcat | last post by:
I have a directory structure that contains different modules that run depending on what the user selects. They are identical in name and structure, but what varies is the content of the functions....
3
by: Chris | last post by:
Hi, 1) In file test.aspx, i put: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="test" %> <%@ import namespace="System.Data"%> <%@ import...
5
by: mark_galeck_spam_magnet | last post by:
Hi, why does complain name 'compileFile' not defined. But works. Why? (I did read the tutorial, it seems to say "import module" should work. Thank you, Mark
1
by: Eric Hanchrow | last post by:
(This is with Python 2.5.2, on Ubuntu Hardy, if it matters.) This seems so basic that I'm surprised that I didn't find anything about it in the FAQ. (Yes, I am fairly new to Python.) Here are...
4
YarrOfDoom
by: YarrOfDoom | last post by:
I just installed wxPython on my computer (Windows "fails-a-lot" Vista, 32bit, Python 2.6, PIL and pyOpenGL installed). However, when I try to import the wxPython module, I get this: >>> import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.