我正在尝试做一些类似新闻源的事情,但要简单得多。只是从顶部填充项目,而旧项目被推下。我正在参考向 Tkinter 中的一组小部件添加滚动条,但这一个在底部添加了新项目,我无法做到这一点,以便始终将最新的滚动条添加到顶部,而旧的在底部。提前谢谢你。 到目前为止,我有这个:
import Tkinter as tk
from Tkinter import *
import PIL
from PIL import Image, ImageTk
root = tk.Tk()
canvas = tk.Canvas(root, borderwidth=0, background="#ffffff")
frame = tk.Frame(canvas, background="#ffffff")
vsb = tk.Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
vsb.pack(side="right", fill="y")
canvas.pack(side="left", fill="both", expand=True)
canvas.create_window((4,4), window=frame, anchor="nw")
row=0
def populate(frame):
global row
row += 1
#image files
imfile = "potato.jpeg"
im=Image.open(imfile)
resized=im.resize((50,50), PIL.Image.ANTIALIAS)
tkimage = ImageTk.PhotoImage(resized)
t="the item number %s tt" %row
tk.Label(frame, text=t, compound=tk.RIGHT).pack()
def onFrameConfigure(canvas):
'''Reset the scroll region to encompass the inner frame'''
canvas.configure(scrollregion=canvas.bbox("all"))
def update_status():
populate(frame)
root.after(1000, update_status)
root.after(1000, update_status)
frame.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas))
root.geometry("500x500")
root.mainloop()
谢谢大家,我发现了:
tk.Label(frame, text=t,image=tkimage, compound=tk.RIGHT).pack(side="bottom")
b=Button(frame, text="see more for %s" %row, command=new_window).pack(side="bottom")