0
我想單擊列表中的項目時顯示圖像,但是當單擊該項目時,只有一個圖像正在顯示所有項目,但特定項目的圖像沒有被加載。綁定列表的內容點擊時顯示圖像
from Tkinter import *
import os
from PIL import Image
root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack(side = RIGHT, fill=Y)
mylist = Listbox(root, font = "verdana 15", yscrollcommand = scrollbar.set, height= 5, width = 10)
def biscuit(self):
bi = Image.open('D://images/biscuit.jpeg')
bi.show()
a = mylist.insert(END,str('Biscuit'))
mylist.bind('<Button>', biscuit)
def chocolate(self):
ch = Image.open('D://images/chocolate.jpeg')
ch.show()
b = mylist.insert(END,str('Chocolate'))
mylist.bind('<Button>', chocolate)
def sandwich(self):
san = Image.open('D://images/sandwich.jpeg')
san.show()
c = mylist.insert(END,str('Sandwich'))
mylist.bind('<Button>', sandwich)
def cake(self):
ca = Image.open('D://images/cake.jpeg')
ca.show()
d = mylist.insert(END,str('Cake'))
mylist.bind('<Button>', cake)
mylist.pack()
scrollbar.config(command = mylist.yview)
mainloop()
Thankz的答案馬克.. u能PLZ闡述如何讓我與sutable關鍵詞的要求是使用.. –
@BharathGupta,請參閱代碼示例。 – Mark
Thankz很多馬克.. –