我正在尝试用python将图像加载到画布中。但是我得到了一个错误:TclError:无法识别图像文件“C:\testimage”中的数据\海绵菌.jpg““
import Tkinter
from Tkinter import *
import time
import inspect
import os
from PIL import Image, ImageTk
class game_one:
def __init__(self):
global root
global canvas_one
root = Tk()
root.title(" Thanks Josh Dark
canvas_one = Tkinter.Canvas(root, bg="BLACK")
canvas_one.pack(expand= YES, fill= BOTH)
canvas_one.focus_set() #allows keyboard events
p = PhotoImage(file="C:\testimage\spongesea.jpg")
canvas_one.create_image(0, 0, image = p, anchor=NW)
root.grab_set()#I forget what this does. Don't change it.
root.lift()#This makes root appear in front of the other applications
ObjectExample = game_one()# starts the animation
我可以从文件中手动打开图像,因此它没有损坏,并且调用的位置正确。有什么想法吗?谢谢
PhotoImage
仅适用于GIF
和PGM/PPM
。你知道吗您必须使用
Image
,ImageTk
来处理其他格式顺便说一句:阅读PhotoImage并查看注释中的“垃圾收集问题”。你知道吗
相关问题 更多 >
编程相关推荐