[Tutor] finding path to resource files in a GUI application

Christian Meesters meesters at uni-mainz.de
Thu Jun 9 08:52:59 CEST 2005


Currently I'm writing a GUI application with wxPython (on OS X, but I  
guess the problem is the same, regardless of the UNIX derivative one is  
using). When I start the main script where it is located the  
application finds all resource files (non-Python files like images and  
html files for html windows) without any problem. However, if a put a  
link in /usr/local/bin and start the script using the link the  
application cannot find those resource files - unless, of course, I  
will use full absolute paths to point to those files. One brief example  
to illustrate the problem:

The class Goals is in a file called Help.py, located in '/gui_lib/' as  
seen from my main script.

class Goals(wx.Frame):
	def __init__(self,parent,frame,title,size,pos=wx.DefaultPosition):
		self.frame = frame
		self.cwd = os.getcwd()	
		self.html = HtmlWindow(self,-1)
#this, of course, won't work
		#if the main script is called from somewhere else and not the  
directory where the main script
		#is located

Any ideas what I could use instead of os.getcwd to construct a relative  
path which will work even if I port the script to an other machine?


More information about the Tutor mailing list