0

Hi, i was wondering if someone could help me out here.
from the below code i get the following error "TclError: couldn't open "H:\SDD12\Images
oses.gif": no such file or directory" but i dont understand why the r is vanishing from the filename...

root = tk.Tk()
root.title('background image')
 
# pick a .gif image file you have in the working directory
image1 = tk.PhotoImage(file="H:\SDD12\Images\roses.gif")
w = image1.width()
h = image1.height()

root.geometry("%dx%d+0+0" % (w, h))
 
# tk.Frame has no image argument
# so use a label as a panel/frame
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
 
button2 = tk.Button(panel1, text='button2')
button2.pack(side='top')
 
# save the panel's image from 'garbage collection'
panel1.image = image1
 
# start the event loop
root.mainloop()
2
Contributors
1
Reply
5
Views
7 Years
Discussion Span
Last Post by pyTony
0

\ is escape character for example '\n' is newline character at end of line.

You can double it, as \\. Also you can use / in path instead of \ unix style.

Mayby cleanest alternative however is to use r before quotes (raw string):

file=r"H:\SDD12\Images\roses.gif"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.