Python Tkinter 错误, "Too Early to Create Image"

标签 python tkinter

所以我有一个任务,我必须使用 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/

相关文章:

python - 是否有一个 python pickle 等效库可以转储 ascii 而不是二进制流?

python - 创建一个带有位域的枚举

python - txpostgres 存储过程返回游标

Python Tkinter : Change scale trough to be multicolor gradient

python - 在 tkinter 的 Canvas 小部件中更改矩形的宽度

python - 在tensorflow python中替换值或创建张量掩码

python - 如何测量矢量的移动角度

python - 将Python代码转换为Linux可执行文件

python - 无法使用 Tkinter 打印出 "event.char"

python - 如何在 Tkinter 中使用列表框打开文本文件