import tkinter as tk
input_text = tk.Text(root)
scroll = tk.Scrollbar(root)
# 注意顺序,先放scroll,再放text
scroll.pack(side=tk.RIGHT, fill=tk.Y)
input_text.pack(side=tk.TOP)
scroll.config(command=input_text.yview)
input_text.config(yscrollcommand=scroll.set)