为什么以下代码不起作用:
root = Tk()
canvas = Canvas(root, width=1500, height=1500)
def createTank(x, y):
tank = PhotoImage(file="Game/tank.gif")
canvas.create_image(x, y, image=tank)
canvas.pack()
createTank(500, 500)
root.mainloop()
运行代码时,我只是得到一个空白的tkinter窗口。为什么?
最佳答案
试试这个代码
from tkinter import *
root = Tk()
canvas = Canvas(root, width=1500, height=1500)
canvas.pack()
tank = PhotoImage(file="Game/tank.gif")
def createTank(x, y):
canvas.create_image(x, y, image=tank)
createTank(500, 500)
root.mainloop()
关于python - Tkinter图像不显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53736236/