【发布时间】:2018-04-17 08:46:25
【问题描述】:
我知道如何创建图像和一个可滚动的列表框,但是当我将这两个元素结合起来时它不起作用。有什么想法可以实现吗?
import tkinter as tk
from PIL import ImageTk, Image
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
text = tk.Text(self, wrap="none")
vsb = tk.Scrollbar(orient="vertical", command=text.yview)
text.configure(yscrollcommand=vsb.set)
vsb.pack(side="right", fill="y")
text.pack(fill="both", expand=True)
for i in range(20):
# b = tk.Button(self, text="Button #%s" % i)
photo = tk.PhotoImage(file='img.png')
photo = photo.subsample(2)
b = tk.Label(self,image=photo)
# b.pack(side='bottom',fill='x')
text.window_create("end", window=b)
text.insert("end", "\n")
text.configure(state="disabled")
if __name__ == "__main__":
root = tk.Tk()
Example(root).pack(fill="both", expand=True)
root.mainloop()
如果可以查看图片列表
b = tk.Label(self,image=photo)
变成这样
b = tk.Label(self,text='test')
【问题讨论】:
-
显示你的代码。
-
我不知道你为什么有这么多底片。这是一个很好的问题,对我帮助很大。谢谢!
标签: tkinter