Scrollbar Basic test

This is an example of the “traditional” use of the Scrollbar widget.  Here it is paired with Text widget inside a LabelFrame widget.  It is worth noting that there is a supporting module called “scrolledtext” that does this work for you though I have noted that Stackover frequent guru Brian Oakley feels we are better off doing it the old fashioned way.  This works great using pack but is somewhat more problematic with grid and we have not tried it with place.

#Scrollbar Test with a Text widget in a LabelFrame
#standard set up header code 2 
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.configure(background='SteelBlue4')
scrW = root.winfo_screenwidth()
scrH = root.winfo_screenheight()  
workwindow = str(1024) + "x" + str(768)+ "+" +str(int((scrW-1024)/2)) + "+" +str(int((scrH-768)/2))
top1 = Toplevel(root, bg="light blue")
top1.geometry(workwindow)
top1.title("Top 1 - Workwindow")
top1.attributes("-topmost", 1)  # make sure top1 is on top to start
root.update()                   # but don't leave it locked in place
top1.attributes("-topmost", 0)  # in case you use lower or lift
#exit button - note: uses grid
b3=Button(root, text="Egress", command=root.destroy)
b3.grid(row=0,column=0,ipadx=10, ipady=10, pady=5, padx=5, sticky = W+N)
#____________________________

# first for some filler text to use
t1text="Lorem ipsum dolor sit amet, consectetur adipiscing elit.\
Mauris non metus ut ligula iaculis placerat eget at eros. Donec id \
dolor facilisis, euismod lectus ac, tincidunt ex. Vestibulum ante \
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; \
Sed ante ante, laoreet vel finibus in, vestibulum sit amet mi. \
In lobortis pretium placerat. Praesent pulvinar arcu at odio vulputate \
lacinia. Fusce tempor ultricies sagittis. Pellentesque habitant morbi \
tristique senectus et netus et malesuada fames ac turpis egestas. \
Vestibulum tincidunt vitae sapien vel blandit. Duis est libero, egestas \
et elementum at, lobortis non justo. Morbi ac risus pellentesque, viverra \
elit quis, commodo felis. Pellentesque pharetra vel diam vitae dictum. \
Etiam at sagittis erat. Nunc sit amet vehicula nulla. Yada yada yada.\
Sed ante ante, laoreet vel finibus in, vestibulum sit amet mi. \
In lobortis pretium placerat. Praesent pulvinar arcu at odio vulputate \
lacinia. Fusce tempor ultricies sagittis. Pellentesque habitant morbi \
tristique senectus et netus et malesuada fames ac turpis egestas. \
Vestibulum tincidunt vitae sapien vel blandit. Duis est libero, egestas \
et elementum at, lobortis non justo. Morbi ac risus pellentesque, viverra \
elit quis, commodo felis. Pellentesque pharetra vel diam vitae dictum."

# NOTE CAREFULLY the ORDER in which the LabelFrame, Scrollbar and
# Text widget are CREATED AND PACKED - does not work any other way!

lf1=LabelFrame(top1, width=225, height=768) #create a LableFrame object -DONT pack

sbar1 = Scrollbar(lf1)    #create a scrollbar and pack in LabelFrame on right
sbar1.pack(side="right", fill="y")
                          #create a text and pack in LabelFrame on left, fill both
t1=Text(lf1, width=40, height=30, wrap=CHAR, yscrollcommand=sbar1.set)
t1.pack(side="left", fill="both", expand=True) #pack it in lf1
t1.insert(END, t1text)                      # then fill it up

sbar1.config(command=t1.yview) #now connect scrollbar and text frame

lf1.grid(row=0, column=0)  # when all that is done, grid the LabelFrame
                           # any other sequence voids propagate
lf1.pack_propagate(False)  #without propagate the text frame expands
#____________________________
root.mainloop()