Python Forum
Invalid argument: 'images\x08ackground.jpg'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid argument: 'images\x08ackground.jpg'
#1
My code:
[Image: d6a4a5c68148a348a654a0a4a7774cfb.png]

The error:
[Image: 67e616fd9ee26818bfe80edb628e9ede.png]

the image:
[Image: d5ab3688d10d955feda970819a273e7d.png]
Larz60+ write Jun-18-2023, 09:12 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
You should post actual code and not images of code. Make sure your image folder is at the project root.

An example

import os, sys
import tkinter as tk
from PIL import Image, ImageTk

# Get executing file path and split at /
file_path = sys.argv[0].split('/')

# pop the file part off
file_path.pop()

# Join the path with /
folder_path = '/'.join(file_path)


class LoginSystem:
    def __init__(self, parent):
        parent.title('Login System')
        parent.geometry('1350x700')

        # Using tk.PhotoImage
        img = tk.PhotoImage(file=f'{folder_path}/images/ratt.png')

        # We need this as not to loose image in the garbage collection
        img.img = img

        # Using PIL
        img2 = ImageTk.PhotoImage(Image.open(f'{folder_path}/images/ratt.png'))

        # As above needed so not to loose image in garbage collection
        img2.backup = img2

        # For the icon
        parent.iconphoto(True, img)

        font = ('None', 16, 'bold')

        # Creating some label frames
        labelframe = tk.LabelFrame(parent, text='Using a Canvas and tk.PhotoImage')
        labelframe['font'] = font
        labelframe.pack(side='left', expand='True', fill='both')

        labelframe2 = tk.LabelFrame(parent, text='Using a Label and tk.PhotoImage')
        labelframe2['font'] = font
        labelframe2.pack(side='left', expand='True', fill='both')

        labelframe3 = tk.LabelFrame(parent, text='Using a Canvas and PIL')
        labelframe3['font'] = font
        labelframe3.pack(side='left', expand='True', fill='both')

        # Creating a canvas for an image
        canvas = tk.Canvas(labelframe)
        canvas.pack(side='left', expand=1, fill='both')

        canvas.create_image(0, 0, anchor='nw', image=img)

        # Using a lable for image
        label = tk.Label(labelframe2, image=img, anchor='nw')
        label.pack(side='left', expand=True, fill='both')

        # Creating a canvas for the third image
        canvas = tk.Canvas(labelframe3)
        canvas.pack(side='left', expand=True, fill='both')

        canvas.create_image(0,0, anchor='nw', image=img2)

        
root = tk.Tk()
LoginSystem(root)
root.mainloop()

More can be found here on tkinter and images
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Try 'images/background.jpg' or r'images\background.jpg' or 'images\\background.jpg'
Reply
#4
\b is an escape sequence for entering the non-viisible ASCII backspace character, thus your background string name is " images<backspace> ackground.jpg".

Of Gribouillis' suggestions I like the forward slash the best. Python will replace with backslashes when it opens the file. The other two suggestions, the double backslash or raw string, are ways of turning off the special meaning a backslash has in a string literal.
Reply
#5
thank you guys!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] [Errno 22] Invalid argument Junaid 0 2,297 Jun-12-2021, 06:02 PM
Last Post: Junaid
  [Errno 22] Invalid argument satyaneel 11 106,315 Jul-14-2020, 08:47 AM
Last Post: lichunming
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,880 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,852 Mar-03-2020, 08:34 AM
Last Post: buran
  Invalid argument error thrown. pyseeker 4 8,624 Sep-10-2019, 07:03 PM
Last Post: pyseeker
  OSError: [Errno 22] Invalid argument - wasn't there last time I ran the code! meganhollie 2 9,221 Jun-11-2018, 06:01 PM
Last Post: meganhollie
  [SOLVED] OSError: [Errno 22] Invalid argument Panda 13 44,034 Jun-04-2018, 08:33 PM
Last Post: volcano63
  [Errno 22] Invalid argument Asafb 8 13,596 Dec-19-2017, 12:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020