0
我試圖在標籤內呈現圖像,但是當我打印標籤時,其中沒有圖像。這是我的代碼。Tkinter Image中的標籤?
from tkinter import *
newGameWindow = Toplevel()
newGameWindow.title("New Game")
newGameWindow.config(bg = "grey")
newGameWindow.geometry('600x600')
courtImg = PhotoImage('basketballCourtTemplate.png')
photo = Label(newGameWindow, image= courtImg, height = 200, width =200)
photo.pack()
newGameWindow.mainloop()
圖像位於與代碼相同的文件中。我是否正確加載圖像?編號: 這段代碼產生完全相同的輸出。
from tkinter import *
newGameWindow = Toplevel()
newGameWindow.title("New Game")
newGameWindow.config(bg = "grey")
newGameWindow.geometry('600x600')
courtImg = PhotoImage('basketballCourtTemplate.gif')
photo = Label(newGameWindow, image= courtImg, height = 200, width =200)
photo.image = courtImg
photo.pack()
newGameWindow.mainloop()
編輯: 它所需要的是courtImg = PhotoImage(file='basketballCourtTemplate.gif')
[爲什麼我的Tkinter圖片不出現?](http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm) – Lafexlos