Reputation: 1
I am learning to use Python and tkinter as a hobby.
I have two systems at different locations: one is XP (SP3) and the other is Win7 (SP1).
The code snippet for this question is as follows:
import tkinter
import sys
print (sys.path)
wnd = tkinter.Tk()
wnd.title("Sinewave's window")
wnd.geometry("250x100+10+30")
#this one works in both XP and Windows7
wnd.wm_iconbitmap('C:\Python34\icons\colours.ico')
#this one works in XP but not in windows 7
#wnd.wm_iconbitmap('./icons/colours.ico') #implied path
wnd.mainloop()
The shell window shows the path as:
['C:/Python34/py scripts', 'C:\\Python34\\py scripts', 'C:\\Python34\\Lib\\idlelib', 'C:\\Windows\\system32\\python34.zip', 'C:\\Python34\\DLLs', 'C:\\Python34\\lib', 'C:\\Python34', 'C:\\Python34\\lib\\site-packages']
The error when I try the "implied" path in Win7 is:
_tkinter.TclError: bitmap "./icons/colours.ico" not defined
I have tried many variations but cannot get the "implied" path to work in Win7.
Am I missing something, or does it just not work like in XP ?
(Of course, to try out this snippet you must create the folder "icons" and define an appropriate icon).
Upvotes: 0
Views: 83
Reputation: 91009
For loading files, the relative path is not relative to sys.path
, it should be relative to your current working directory.
sys.path
is used when python imports modules , its not used for loading files or for tkinter.
For file openning and all only the current working directory is considered (unless you have given complete aboslute path).
So the issue must be occuring in Windows 7 , because there may not be a icons/colours.ico
file relative to the directory from which you run the script. It may be present in case of Windows XP.
Upvotes: 1