import tkinter as tk root = tk.Tk()
root.geometry("900x600")
text = tk.Text(root,width=90, height=40,bg=root['background'],bd=0) # width 是设置的宽的10%最好 # 设置边框为0,背景颜色随父容器的背景,可实现融为一体 text.pack(side="left", fill=tk.Y) sb = tk.Scrollbar(root, command=text.yview) sb.pack(side="right", fill=tk.Y) text.configure(yscrollcommand=sb.set) fm = tk.Frame(text) for i in range(100): button = tk.Button(fm, text=i, width=2).pack() # 重点!组件的父对象(容器)为Frame,Frame的父对象为Text,Text的父对象为Tk或Topleval text.window_create("end", window=fm) text.insert("end", "\n") text.configure(state="disabled") root.geometry('1150x1150') root.mainloop()