Python Tkinter错误,“太早创建图像”

发布于 2021-01-29 18:59:35

因此,我必须使用Tkinter来创建棋盘游戏。这只是程序的一部分,我想在其中引入董事会形象。但是我不断收到错误消息:“创建图像为时过早”,我不确定自己做错了什么。

到目前为止,这是我的代码:

from Tkinter import *
from pprint import pprint

# Which variable is currently updating
from variableColors import Variables
VariableIndex = 0               
VariableText = Variables[VariableIndex]

Ids = None             # Current canvas ids of the text and 4 player tokens:
                       # Will be None if not committed

VariableCoords = { }       # Where store variable and coordinates


im = PhotoImage(file="C:\Users\Kiki\Desktop\Assignment\\")
photo = can.create_image(0,0,anchor=NW, image=im)

can.pack()


root.mainloop()

任何帮助,将不胜感激。谢谢 :)

关注者
0
被浏览
85
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    您忘记声明root- root = Tk()。使用前,Tk系统必须打开。



推荐阅读
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看