I am trying to place a scrollbar on the bottom frame of my window. When I run this code, the scrollbar is placed in the middle of the screen and very small, until I use my mouse wheel and actually scroll around, then it goes to the right side of the screen and acts normally. Although, for some reason also when it goes to the right side of the screen, there is then a white border around my bottom frame, which is very frustrating.
I need help getting my scrollbar to appear on the right side of the bottom frame as well as not having the white border around my bottom frame.
import tkinter as tk
def onFrameConfigure(canvas):
'''Reset the scroll region to encompass the inner frame'''
canvas.configure(scrollregion=canvas.bbox('all'))
def gui_setup(root):
root.title('Test')
root.config(bg='snow3')
root.minsize(600, 700)
top_frame = tk.Frame(root, width=600, height=300)
top_frame.grid(row=0, column=0)
btm_frame = tk.Frame(root, width=600, height=400)
btm_frame.config(bg='snow3', borderwidth=0)
btm_frame.grid(row=2, column=0)
global bottom_area
global canvas
canvas = tk.Canvas(btm_frame, borderwidth=0, background='snow3')
canvas.config(width=600, height=420)
bottom_area = tk.Frame(canvas, background='snow3', borderwidth=0)
scroll = tk.Scrollbar(canvas, orient='vertical', command=canvas.yview)
canvas.config(yscrollcommand=scroll.set)
scroll.pack(side='right', fill='y')
def on_mouseWheel(event):
shift = (event.state & 0x1) != 0
scroll_action = -1 if event.delta > 0 else 1
if shift:
canvas.xview_scroll(scroll_action, 'units')
else:
canvas.yview_scroll(scroll_action, 'units')
canvas.pack(side='left', fill='both', expand=True)
canvas.create_window((4,4), window=bottom_area, anchor='nw')
bottom_area.bind('<Configure>', lambda event, canvas=canvas: onFrameConfigure(canvas=canvas))
bottom_area.bind_all('<MouseWheel>', on_mouseWheel)
root = tk.Tk()
gui_setup(root)
tk.mainloop()