Jun-18-2023, 10:52 AM
Jun-18-2023, 11:28 AM
You should post actual code and not images of code. Make sure your image folder is at the project root.
An example
More can be found here on tkinter and images
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
Jun-18-2023, 12:05 PM
Try
'images/background.jpg'
or r'images\background.jpg'
or 'images\\background.jpg'
Jun-18-2023, 12:42 PM
\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.
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.
Jun-19-2023, 09:28 AM
thank you guys!