Re: Tkinter PhotoImage, no such file or directory

"Luke Dunstan" <[email protected]>
Newsgroups gmane.comp.python.windows-ce
Message-ID <[email protected]>
----- Original Message ----- 
From: "Michael Foord" <[email protected]>
To: "Patrick Kramer" <[email protected]>
Cc: <[email protected]>
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


Correct.

> 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.
>
> HTH
>
> Fuzzyman
> http://www.voidspace.org.uk/python/shareware.shtml

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

Luke
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.