0

I'm back here with a new error that I can't solve... it's a strange error, idk, I put the images in the same directory of the program, in the directory specified in the code... Ah, I don't know, but this is all the code:

from tkinter import *
def toggle_fs():
    """
    Function that enables fullscreen for the window I create
    """
    state = False if root.attributes('-fullscreen') else True
    root.attributes('-fullscreen', state)
    if not state:
        root.geometry('300x300+100+100')


print("Inserisci il nome della foto: ") # Enter the name of the image -> "ImmagineProva"
nomeImg = input()


def getImg(nomeImg):
    """
    Function that obtaines the right image, because I have different images that are all the same picture but all are different in resolution (1360x768, 1920x1080...)
    """

    # detect the resolution of the monitor
    WIDTH, HEIGHT = root.winfo_screenwidth(), root.winfo_screenheight()

    # Takes the right image thanks to its name and screen resolution took before
    img = PhotoImage(file = "ImmaginiDiProva/" + nomeImg + str(WIDTH) + "x" + str(HEIGHT) + ".png")

    # All the images have the same name "ImmagineProva" with the relative resolution
    return img


root = Tk(screenName = "Prova")
root.attributes("-fullscreen", True)

canvas = Canvas(root, bg = "white")
canvas.pack(fill = BOTH, expand = True)

img = getImg(nomeImg)
canvas.create_image(0, 0, anchor = NW, image = img)

root.bind("<Escape>", toggle_fs())

mainloop()

I hope this is enough for you... I'm frustrated, I put the images everywhere and it doesn't recognize them, wtf O.o

Seintian
  • 151
  • 1
  • 1
  • 11
  • I don't see anything wrong with your code, so you either do not have that specific size as an image, or you have a small typo, or you do not have permission to load the images. You can check the first 2 options if you add this line and show us the result: `import os; print(os.listdir("ImmaginiDiProva"))`. – Novel Dec 01 '20 at 22:34
  • If python gives you a "no such file or directory" error, you can be certain it is telling you the truth. Often that means you're assuming that relative paths are relative to the file rather than relative to the working directory. – Bryan Oakley Dec 01 '20 at 22:38

1 Answers1

0

I read the comments, so I post an image so you'll be able to see everything about the program, images...

An image of the folder of the program

Ah, I did what said the utent in the comment (I don't remember the nick and the page doesn't make me scroll up lol) -> import os; print(etc...) and raised the error FileNotFoundError: [WinError 3] Impossibile trovare il percorso specificato: 'ImmaginiDiProva'

Why this? there is also the folder in the image I posted... I don't understand ahahah

Thank you guys for your help, by the way <3

Seintian
  • 151
  • 1
  • 1
  • 11