[PythonCE] Tkinter PhotoImage, no such file or directory

Michael Foord fuzzyman at voidspace.org.uk
Fri Apr 28 14:35:36 CEST 2006


Patrick Kramer wrote:
> I have two files which are both in the PyGlucoCE directory off of root.
>
> Tkintertest.py
> BtnGluco.gif
>
>
>
> Here is my code:
>
> import sys
>
> sys.path.append('\\Program Files\\Python24\\python24.zip\\lib-tk')
> sys.path.append('\\PyGlucoCE')
>   

This appends the PyGluoCE directory to sys.path.
> from Tkinter import *
>
> root = Tk()
>
> ImgGlucose = PhotoImage(file = 'BtnGluco.gif')
>   
This tells PhotoImage to fetch the file 'BtnGluco.gif' from the current 
directory. This is your problem I believe. Pass an absolute path here 
and it should go away.



> print ImgGlucose.height()
>
> b = Button(root, image=ImgGlucose)
> b.image = ImgGlucose
> b.pack()
>
> root.mainloop()
>
>
>
> Now I get this error:
>
> _tkinter.TclError: couldn't open "BtnGluco.gif": no such file or directory
>
>
>
>
> The weird part is I get the same error within Pydev, but if I run the script straight through commandline, it works and shows the image as a button.
>
>   
Probably because you run the script from inside that directory on your 
desktop.

PythonCE starts with the current directory somewhere else.

> My guess is I screwed up the path append, but it looks correct to me :/
>   
I'm pretty sure that Tkinter *doesn't* search sys.path for image files.

HTH

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> _______________________________________________
> PythonCE mailing list
> PythonCE at python.org
> http://mail.python.org/mailman/listinfo/pythonce
>
>   



More information about the PythonCE mailing list