PythonImageTk工作时出错

2024-05-19 14:30:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经运行了一个GUI,ImageTK已经被使用了3次,但每次我使用它添加新行时,该行都会给出一个NameError:

NameError: name 'ImageTK' is not defined

它正确运行的示例(在显示掷骰子的函数中):

img = Image.open("{}.png".format(rand_num))
die_img = ImageTk.PhotoImage(img)
die.config(image=die_img)
die.update()

img = Image.open("pb.png")
grave_img = ImageTK.PhotoImage(img)
pb1.config(image=grave_img)
pb1.update()

所以它存在,然后它就不存在了。帮助


Tags: imageconfigimgpngupdateguiopen行时