Scrollbar into a python tkinter discussion
Question: 
    from tkinter import *
    
    window = Tk()
    
    ia_answers= "test\n"
    input_frame = LabelFrame(window, text="User :", borderwidth=4)
    input_frame.pack(fill=BOTH, side=BOTTOM)
    
    input_user = StringVar()
    input_field = Entry(input_frame, text=input_user)
    input_field.pack(fill=BOTH, side=BOTTOM)
    
    def onFrameConfigure(canvas):
    '''Reset the scroll region to encompass the inner frame'''
        canvas.configure(scrollregion=canvas.bbox("all"))
    canvas = Canvas(window, borderwidth=0, background="white")
    ia_frame = LabelFrame(canvas, text="Discussion",borderwidth = 15, height = 100, width = 100)
    ia_frame.pack(fill=BOTH, side=TOP)
    scroll = Scrollbar(window, orient="vertical", command=canvas.yview)
    canvas.configure(yscrollcommand=scroll.set)
    
    scroll.pack(side=RIGHT, fill=Y)
    canvas.pack(fill=BOTH, expand=True)
    canvas.create_window((4,4), window=ia_frame, anchor="nw")
    ia_frame.bind("<Configure>", lambda event, canvas=canvas:onFrameConfigure(canvas))
    
    
    
    
    user_says = StringVar()
    user_text = Label(ia_frame, textvariable=user_says, anchor = NE, justify =   RIGHT, bg="white") 
    user_text.pack(fill=X) 
    
    ia_says = StringVar()
    ia_text = Label(ia_frame, textvariable=ia_says, anchor = NW, justify = LEFT, bg="white") 
    ia_text.pack(fill=X) 
    
    user_texts = []
    ia_texts = []
    user_says_list = []
    ia_says_list = []
    def Enter_pressed(event):
        """Took the current string in the Entry field."""
        input_get = input_field.get()
        input_user.set("")
        user_says1 = StringVar()
        user_says1.set(input_get + "\n")
        user_text1 = Label(ia_frame, textvariable=user_says1, anchor = NE, justify =   RIGHT, bg="white") 
        user_text1.pack(fill=X)
        user_texts.append(user_text1)
        user_says_list.append(user_says1)
        ia_says1 = StringVar()
        ia_says1.set(ia_answers)
        ia_text1 = Label(ia_frame, textvariable=ia_says1, anchor = NW, justify = LEFT, bg="white") 
        ia_text1.pack(fill=X)
        ia_texts.append(ia_text1)
        ia_says_list.append(ia_says1)
    
    input_field.bind("<Return>", Enter_pressed)
    window.mainloop()
    

Hi, I try to build a GUI with tkinter but I've got two problems, the
LabelFrame/Canvas doesn't fill entirely the window and I can't get the
scrollbar to automatically scroll down. Can you help me with that, thank you
very much. Ilan Rossler.


Answer: You need to manually control the width of the inner frame since it is being
managed by the canvas. You can change the width in a binding to the
`<Configure>` event of the canvas (ie: when the canvas changes size, you must
change the size of the frame).

You'll need to be able to reference the window object on the canvas, which
means you need to save the id, or give it a tag.

Here's an example of giving it a tag:

    
    
    canvas.create_window((4,4), window=ia_frame, anchor="nw", tags=("innerFrame",))
    

And here's how to change the width when the canvas changes size:

    
    
    def onCanvasConfigure(event):
        canvas = event.widget
        canvas.itemconfigure("innerFrame", width=canvas.winfo_width() - 8)
    
    canvas.bind("<Configure>", onCanvasConfigure)
    

To scroll down, call the `yview` command just like the scrollbar does. You
need to make this happen _after_ the window has had a chance to refresh.

For example, add this as the very last line in `Enter_pressed`:

    
    
    def Enter_pressed(event):
        ...
        canvas.after_idle(canvas.yview_moveto, 1.0)
    

