0

I am trying to do something like newsfeed but much simpler. Just items getting populated from the top, and old items are pushed down. I am taking reference from Adding a scrollbar to a group of widgets in Tkinter but this one adds new item on the bottom, and I could not make it so that the newest one is always added on top and old ones are on the bottom. Thank you in advance. I have this so far:

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 \t\t" %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()

1 Answers1

0

Thanks guys, I found it out:

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