tkinter pack vs grid methods: Scrollbar appearances
13:22 04 Mar 2020

Below shows the right bottom corner of a Tk window that consists of a frame that consists of a Canvas and horizontal and vertical scrollbars. This was achieved using the Grid method.

Right bottom corner by the Grid method.

I am not able to replicate the same look using the Pack method. Below is what I get and the sample code giving such a look.

Right bottom corner by the Pack method.

How do I replicate the look by the grid method using the pack method?

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()
frame = ttk.Frame( root )
frame.pack()

ysb = ttk.Scrollbar( frame, orient='vertical' )
xsb = ttk.Scrollbar( frame, orient='horizontal' )

canvas = tk.Canvas( frame, width=1000, height=700, background='green')
canvas.create_rectangle( 100, 100, 900, 600, fill='yellow' )
canvas.configure( scrollregion=canvas.bbox(tk.ALL),
                  xscrollcommand=xsb.set,
                  yscrollcommand=ysb.set )

xsb.config( command=canvas.xview )
ysb.config( command=canvas.yview )

ysb.pack( side='right', fill='y', expand=1)
xsb.pack( side='bottom', fill='x', expand=1 )
canvas.pack( side='left', fill='both', expand=1 )

#ysb.grid( row=0, column=1, sticky='ns' )
#xsb.grid( row=1, column=0, sticky='ew' )
#canvas.grid( row=0, column=0, sticky='nsew' )
python tkinter scrollbar