我又回来了一个我无法解决的新错误...这是一个奇怪的错误,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