March 28th, 2013, 04:01 PM
-
Importing wxpython
Can someone help plse Am in my very early stages second day of learning this language trying to import wx but keep getting an error No module named 'wx'? the problem is I do not know how to enter a pathname that places wxPython on the PythonPath. plse help
March 28th, 2013, 09:18 PM
-
You'd need to know the location of this "wx" module. There could be a directory containing the file __init__.py
Or there might be a file called wx.py
Or some other possibilities.
If P is the path to that directory's parent,
import sys
sys.path.append(P)
where P is a string.
If you're on a windows system the latter statement will probably look like
sys.path.append(r'c:\some\path')
If on a unix like system without weird characters in the path the latter statement will look more like
sys.path.append('/usr/local/python3.2/lib/some/path')
Or on unix
Code:
$ PYTHONPATH=/some/path:$PYTHONPATH python3
and you could put PYTHONPATH into your shell startup script.
[code]
Code tags[/code] are essential for python code and Makefiles!
March 30th, 2013, 09:50 AM
-
importing wxpython
[Being in my early stages everything is still very difficult for me to understand or know what really needs to be done. I am using windows Vista so could you someone plse put out for me how I will conqure this prolem of importing wxpython. Am still getting the same error no module named 'wx'. I seem not to know exactly how to create a path name that will solve my problem.
Plse help am really stuck.
March 30th, 2013, 10:26 AM
-
wxpython is some sort of GUI builder?
I encourage you to learn how to use python---how to use the various data container objects and their purpose, and get a feel for the syntax before continuing with a major project.
[code]
Code tags[/code] are essential for python code and Makefiles!
March 30th, 2013, 07:22 PM
-
What version of Python are you using?
For Python27 you can download the Window installer
http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.12.1-py27.exe
Run the .exe file and it will install the wx package for instance into folder
C:\Python27\Lib\site-packages\wx-2.9.1-msw\wx
Python will find folder wx now.
Last edited by Dietrich; March 31st, 2013 at 02:43 PM.
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
April 2nd, 2013, 06:45 AM
-
Many Thanx
I would like to thank you very much for your Advice .It worked and You have actually changed my life fro now on .Many thanks Again Wonderful Advice for ever greatful.
April 2nd, 2013, 10:34 AM
-
Alright! Now you can test this code ...
Code:
import wx
import wx.lib.filebrowsebutton
class MyFrame(wx.Frame):
def __init__(self, parent, mytitle, mysize):
wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle,
size=mysize)
self.SetBackgroundColour("green")
panel = wx.Panel(self)
# this file browser masked to look for .wav sound files
self.fbb = wx.lib.filebrowsebutton.FileBrowseButton(panel,
labelText="Select a WAVE file:", fileMask="*.wav")
play_button = wx.Button(panel, wx.ID_ANY, ">> Play")
self.Bind(wx.EVT_BUTTON, self.onPlay, play_button)
# setup the layout with sizers
hsizer = wx.BoxSizer(wx.HORIZONTAL)
hsizer.Add(self.fbb, 1, wx.ALIGN_CENTER_VERTICAL)
hsizer.Add(play_button, 0, wx.ALIGN_CENTER_VERTICAL)
# create a border space
border = wx.BoxSizer(wx.VERTICAL)
border.Add(hsizer, 0, wx.EXPAND|wx.ALL, 10)
panel.SetSizer(border)
def onPlay(self, evt):
filename = self.fbb.GetValue()
self.sound = wx.Sound(filename)
# error handling ...
if self.sound.IsOk():
self.sound.Play(wx.SOUND_ASYNC)
else:
wx.MessageBox("Missing or invalid sound file", "Error")
app = wx.App()
# create a MyFrame instance and show the frame
mytitle = "wx.lib.filebrowsebutton.FileBrowseButton and wx.Sound"
width = 600
height = 90
MyFrame(None, mytitle, (width, height)).Show()
app.MainLoop()
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25