0

我又回来了一个我无法解决的新错误...这是一个奇怪的错误,idk,我将图像放在程序的同一目录中,在代码中指定的目录中...啊,我不知道,但这是所有代码:

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

我希望这对你来说已经足够了......我很沮丧,我把图像放在任何地方,但它无法识别它们,wtf Oo

4

1 回答 1

0

我阅读了评论,所以我发布了一张图片,这样您就可以看到有关该程序的所有内容,图片...

程序文件夹的图像

啊,我做了评论中所说的(我不记得昵称,页面不会让我向上滚动哈哈)->import os; print(etc...)并引发了错误FileNotFoundError: [WinError 3] Impossibile trovare il percorso specificato: 'ImmaginiDiProva'

为什么这个?我发布的图片中还有文件夹...我不明白啊哈哈

谢谢你们的帮助,顺便说一句<3

于 2020-12-02T17:42:27.723 回答