标签上的图像?

2024-06-02 07:23:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图呈现一个标签内的图像,虽然当我打印标签时,里面没有图像。这是我的密码。在

from tkinter import *
newGameWindow = Toplevel()
newGameWindow.title("New Game")
newGameWindow.config(bg = "grey")
newGameWindow.geometry('600x600')


#courtImg = PhotoImage('basketballCourtTemplate.png')
courtImg = PhotoImage(file ='basketballCourtTemplate.png')


photo = Label(newGameWindow, image= courtImg, height = 200, width =200)

photo.pack()

newGameWindow.mainloop()

图像与代码位于同一个文件中。我是否正确加载图像?在

编辑: 此代码生成完全相同的输出。在

^{pr2}$

编辑: 它只需要courtImg = PhotoImage(file='basketballCourtTemplate.gif')


Tags: from图像import编辑密码pngtkinter标签