473,595 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SetTopWind ow(frame)
return true

app = MyApp(0)
app.MainLoop()
Jul 19 '05 #1
9 4969
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.Fr ame):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wx.DEFAUL T_FRAME_STYLE|w x.NO_FULL_REPAI NT_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(wxFra me):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wxDEFAULT _FRAME_STYLE|wx NO_FULL_REPAINT _ON_RESIZE):
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"...doe s 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.Fr ame):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wx.DEFAUL T_FRAME_STYLE|w x.NO_FULL_REPAI NT_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(wxFra me):
def __init__(self, parent, id=-1, title="Test Wx", size=(-1, -1),
pos=(-1,-1), style=wxDEFAULT _FRAME_STYLE|wx NO_FULL_REPAINT _ON_RESIZE):
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
2568
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 wxGetFreeMemory()". Since wxGetFreeMemory() seemed effectively unused in gtk, I just commented it out in misc_wrap.cpp (didn't want to patch SWIG to regenerate the wrapper code, so hacked the generated cpp source), and replaced...
0
2703
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 to obtain SHIP_wrap.cpp and SHIP.py; the latter contains the line "import _SHIP". I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
2
4551
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
2591
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
5413
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. They will only need to be run once per execution. Example (directory level): Sys1: A B C
3
2289
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 namespace="System.Data.OleDb"%> .... In file test.aspx.vb, i put:
5
2168
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
1979
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 three tiny files: ==== mut.py ==== import system
4
3611
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 wxPython Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import wxPython File "C:\Python26\lib\site-packages\wx-2.8-msw-ansi\wxPython\__init__.py", line 7, in <module> DeprecationWarning, stacklevel=2)
0
7882
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8250
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5837
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5416
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3908
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1490
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.