所以我有一个任务,我必须使用 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()
如有任何帮助,我们将不胜感激。谢谢:)
最佳答案
您忘记声明根 - root = Tk()
。
Tk 系统必须在使用前打开。
关于Python Tkinter 错误, "Too Early to Create Image",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10236857/