2016-11-18 1 views
0

라벨을 인쇄 할 때 라벨 안에 이미지가 없는데도 이미지를 라벨 안에 표시하려고합니다. 여기 내 코드가있다.Tkinter 레이블에있는 이미지?

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')

+0

[왜 내 Tkinter 이미지가 나타나지 않습니까?] (http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm) – Lafexlos

답변

-1

는, 광 화상은 PNG, JPG 또는 등 그것은 당신의 OS에 따라 달라을 추가 지원했다. Mac OS를 사용하기 시작했을 때 같은 문제에 직면했습니다.

관련 문제