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()

\ 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"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.