[英]Tkinter PhotoImage doesn't exist
當我偶然發現一個錯誤時,我試圖讓我的應用程序的運動原型工作,這是與 Tkinter 的 PhotoImage。
起初,我決定使用 Pathlib,但我開始相信這是一個錯誤(我仍然需要一種方法讓非 Windows 用戶使用此應用程序)。
## -- Setup -- ##
# Imports and Variables
from pathlib import Path # Increases accessibility on mac and Linux machines
from tkinter import *
window = Tk()
window.title("Project 001 - Pre-Alpha 0.1 (pa0.1)")
Game = Canvas(window, width = 1280, height = 720)
Game.config(bg = "white")
Game.pack()
# Defining Images
PlayerImgPath = Path("Assets\\Char\\Player\\Untitled.png") # Player
PlayerImg = PhotoImage(file = PlayerImgPath)
# Sprites
Player = Game.create_image(20, 250, image = PlayerImg)
運行此程序時出現以下錯誤
file "D:\PythonD\lib\tkinter\__init__.py", line 3495, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "Assets\Char\Player\Untitled.png": no such file or directory
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.