2017-09-30 1 views
-2

Tkinter에서 TreeView를 만들고 있습니다. Python 3.4 크롬 로고를 추가했지만 이미지가 나타나지 않습니다.TreeView의 이미지가 Tkinter를 표시하지 않습니다.

treeview=ttk.Treeview(frame3) 
chromelogo=PhotoImage(file="./Images/minor-logo.png") 

chromelogo=chromelogo.subsample(10,10) 

treeview.pack(fill=BOTH,expand=True) 
treeview.insert('','0','Chrome',text='Chrome', image=chromelogo) 

treeview.insert('Chrome','0',"shit",text="shit",image=chromelogo) 

treeview.insert('','1','Chrome3',text='Chrome3') 

크롬 로고 링크 : 당신은 PIL 모듈을 시도는 Tkinter에서 이미지보다는 GIF를 열려면 http://logos-download.com/wp-content/uploads/2016/05/Chrome_icon_bright.png

답변

0

광 화상 당신에게 열려있는 이미지 대신하는 GIF 형식을 허용하지 않습니다. 이 크기를 조정하고

from tkinter import * 
from tkinter import ttk 
from PIL import ImageTk,Image 
win=Tk() 


chromelogo=Image.open("./Images/minor-logo.png")#open the image using PIL 
imwidth=10#the new width you want 

#the next three lines of codes are used to keep the aspect ration of the image 
wpersent=(imwidth/float(chromelogo.size[0])) 
hsize=int(float(chromelogo.size[1])*float(wpersent))#size[1] means the height and the size[0] means the width you can read more about this in th PIL documentation 
chromelogo=ImageTk.PhotoImage(chromelogo.resize((imwidth,hsize),Image.ANTIALIAS))# set the width and put it back in the chromelogo variable 

treeview=ttk.Treeview(win) 
treeview.pack(fill=BOTH,expand=False) 
treeview.insert('','0','Chrome',text='Chrome', image=chromelogo) 
treeview.image = chromelogo#this one is for telling tkinter not to count the image as garbage 
treeview.grid(row=0,rowspan=2,columnspan=2,padx=220,sticky=N+W,pady=20) 

chromelogo2=ImageTk.PhotoImage(Image.open("./Images/minor-logo.png")) 
treeview.insert('Chrome','0',"shit",text="shit",image=chromelogo2)#here you can also insert the unresized logo so you could see it as big as it is 

treeview.insert('','1','Chrome3',text='Chrome3') 

win.mainloop() 
+0

내가 열 삽입 트리 뷰의 사용 피트 이미지를 원하기 때문에 당신은 PIL 모듈을 설치하기 위해 어떤 방법을 사용할 수 있습니다, 내가 명령 줄

python -m pip install pillow 

좋아 up 페인트는 gif로 이미지를 저장했습니다. aas ./Images/chrome.gif 여전히 효과 없음 – zzz123

+0

다른 조언이 있습니까? – zzz123

관련 문제