[PythonCE] Tkinter PhotoImage, no such file or directory

Luke Dunstan coder_infidel at hotmail.com
Sun Apr 30 18:20:44 CEST 2006

----- Original Message ----- 
From: "Michael Foord" <fuzzyman at voidspace.org.uk>
To: "Patrick Kramer" <pkramer at meton.net>
Cc: <pythonce at python.org>
Sent: Sunday, April 30, 2006 5:57 PM
Subject: Re: [PythonCE] Tkinter PhotoImage, no such file or directory

> Patrick Kramer wrote:
>> <quote who="Luke Dunstan">
>>> You can tell Python using os.chdir(), but that will not necessarily have 
>>> any
>>> effect on Tkinter because the operating system has no concept of a 
>>> "current
>>> directory", so it depends on whether the image file is opened in the 
>>> Python
>>> code or the C code.
>>> Luke
>> So there is no way for python to return the current directory it is in?
>> say something like:
>> dir = return_dir()
>> image_loc = dir + "//BtnGluco.gif"
>> Or:
>> image_loc = dir + "//assets//img//BtnGluco.gif" #This is how I would like 
>> to orgnize it
> I think the situation is (perhaps Luke can correct me if I'm wrong) :
> The underlying Windows CE platform has no concept of a current directory.
> PythonCE *simulates* a current directory on the python level


> This means that calls that use only Python code will work as normal -
> except the current directory will always start in a fixed location
> ('//Temp' I think).

That is true at the moment, but in the next release I will change it so that 
if you run a script using the command line then the current directory will 
initially be set to the directory containing the script, for convenience.

> Calls to use files from C code will not have access to this information.
> So you can experiment with the image_loc and see if it works using the
> current directory or not, but it may not do.
> To get the current directory you use the normal functions provided by
> the ``os`` and ``os.path`` module :
> cur_dir = os.getcwd()
> print cur_dir
> os.chdir(""//assets")
> print os.getcwd()

Correct, except that the path separator is \ (or \\ in a string literal) not 

> image_path = os.path.join(os.getcwd(), "img//BtnGluco.gif")

or continuing with that pattern:

image_path = os.path.join(os.getcwd(), "img", "BtnGluco.gif")

> You can also test whether you are running on windows CE or not with either 
> :
> sys.platform or sys.getwindowsversion()
> They should return different things on windows CE and normal windows.
> That means you can make your code behave appropriately depending on
> which system it is on.
> Fuzzyman
> http://www.voidspace.org.uk/python/shareware.shtml

That will work, but like Gonzalo I prefer using os.name.


More information about the PythonCE mailing list