Python tkinter中使用的pygame加载图像;不';“不存在”;

Python tkinter中使用的pygame加载图像;不';“不存在”;,python,python-3.x,tkinter,pygame,Python,Python 3.x,Tkinter,Pygame,首先,我是Python新手,我承认我的代码没有组织。但与实际问题相关的是,基本上我使用pygame将图像加载到变量中。我正在tkinter的顶层使用该图像。当我试图在顶层的标签中使用图像时,它会说它不存在。我正在使用我在某些领域创建的一个模块,但我不认为它有任何关系,所以我不包括它 import tkinter as tk from myfunctions import * import pygame master = tk.Tk() master.resizable(0,0) info

首先,我是Python新手,我承认我的代码没有组织。但与实际问题相关的是,基本上我使用pygame将图像加载到变量中。我正在tkinter的顶层使用该图像。当我试图在顶层的标签中使用图像时,它会说它不存在。我正在使用我在某些领域创建的一个模块,但我不认为它有任何关系,所以我不包括它

import tkinter as tk
from myfunctions import *
import pygame



master = tk.Tk()
master.resizable(0,0)

info = "Guess a number between \n 1 and 99 inclusive!"


f=tk.Frame(master, width=500, height=450)
f.pack_propagate(0)
f.pack()

l=tk.Label(f, text=info, font=("Arial", 30))
l.pack()

heat=tk.Label(f, font=("Arial", 24), fg="red", pady=30)
heat.pack()

f2= tk.Frame(f)
f2.pack()

spinbox = tk.Spinbox(f2, from_= 1, to = 99)
spinbox.pack()

bframe=tk.Frame(f, pady =30)
bframe.pack()

def itsago():
    valid = validcheck(spinbox.get())
    if valid == 0:
        heat.config(text="Not a valid input")
        heat.pack()
    else:
        hcheck = hiddencheck(valid)
        heat.config(text=hcheck)
        heat.pack()
        if hcheck == "You won!\n Re-Open the program to play again.":
            pwin= tk.Toplevel()
            pwin.resizable(0, 0)
            sloth = pygame.image.load('paradesloth.png')
            lparade = tk.Label(pwin, anchor = "nw")
            lparade.config(image = sloth)
            lparade.image = sloth
            lparade.pack()
            pwin.mainloop()


b = tk.Button(bframe, command = itsago, text="Check Number", font=("Arial", 20),       bg="white")
b.pack()



master.mainloop()
任何帮助都将不胜感激:)

*编辑:忘记添加最重要的内容之一,错误:

File "C:\Python33\lib\tkinter\__init__.py", line 1254, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: image "<Surface(800x599x24 SW)>" doesn't exist
文件“C:\Python33\lib\tkinter\\ uuuuu init\ uuuuu.py”,第1254行,在配置中
self.tk.call(_flatten((self._w,cmd))+self._选项(cnf))
_tkinter.TclError:映像“”不存在

由martineau在评论中回答:

pygame.image.load()返回一个pygame.surface对象,该对象与tk.PhotoImage对象不同——它们不能互换马提诺8分钟前


pygame.image.load()
返回一个
pygame.surface
对象,它与
tk.PhotoImage
对象不同——它们不能互换。感谢您的回复:)。pygame的图像加载对我来说更方便,因为tk.PhotoImage似乎只支持GIF。有没有什么方法可以集成pygame的图像加载器,或者我应该将图像转换成gif?没关系,转换成gif看起来很好。由于某种原因,PhotoImage昨天对我不起作用,但显然我做了某种改变,解决了真正的问题。非常感谢马蒂诺!:)有一个模块,可以创建
tk.PhotoImage
对象和
PIL
支持。有关更多信息,请参阅。明白了吗?;-)谢谢,不过我正在使用Python3.3,我认为PIL还不支持:)