Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter错误;“创建图像为时过早”;_Python_Tkinter - Fatal编程技术网

Python Tkinter错误;“创建图像为时过早”;

Python Tkinter错误;“创建图像为时过早”;,python,tkinter,Python,Tkinter,所以我有一个任务,我必须使用Tkinter来创建一个棋盘游戏。这只是程序的一部分,我想在其中引入董事会的形象。但我不断地犯错误,“创建图像为时过早”,我不确定自己做错了什么 以下是我目前的代码: from Tkinter import * from pprint import pprint # Which variable is currently updating from variableColors import Variables VariableIndex = 0

所以我有一个任务,我必须使用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-
root=Tk()

Tk系统在使用前必须打开。

有没有办法检查Tk是否打开?