In this video I’ll show you how to link multiple widgets, like text boxes, with one scrollbar.

This method will work with anything that uses a Scrollbar with Tkinter (listboxes, frames, textboxes, anything at all).

We’ll create a custom function and pass in some *args to make this all work.

Python Code: textscroll.py
(Github Code)

from tkinter import *

root = Tk()
root.title('Codemy.com - Multiple Text Scrolls')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("600x500")

# Yview Function
def multiple_yview(*args):
	my_text1.yview(*args)
	my_text2.yview(*args)
	#print(*args)

# Frame
my_frame = Frame(root)
my_frame.pack(pady=20)

# Create our Scrollbar
text_scroll = Scrollbar(my_frame)
text_scroll.pack(side=RIGHT, fill=Y)

# Create Two Text Boxes
my_text1 = Text(my_frame, width=20, height=25, font=("Helvetica", 16), yscrollcommand=text_scroll.set, wrap="none")
my_text1.pack(side=RIGHT, padx=5)
my_text2 = Text(my_frame, width=20, height=25, font=("Helvetica", 16), yscrollcommand=text_scroll.set, wrap="none")
my_text2.pack(side=LEFT)

# Configure Scrollbar
text_scroll.config(command=multiple_yview)


root.mainloop()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...