我正在尝试将垂直滚动条和水平滚动条添加到框架中。这是我的代码:
rom tkinter import *
from tkinter import ttk
root = Tk()
root.geometry('500x400')
main_frame = Frame(root)
main_frame.pack(fill=BOTH, expand=1)
canvas = Canvas(main_frame)
canvas.pack(side=LEFT, fill=BOTH, expand=1)
vscrollbar = ttk.Scrollbar(main_frame, orient=VERTICAL, command=canvas.yview)
vscrollbar.pack(side=RIGHT, fill=Y)
canvas.configure(yscrollcommand=vscrollbar.set)
hscrollbar = ttk.Scrollbar(main_frame, orient=HORIZONTAL, command=canvas.xview)
hscrollbar.pack(side=BOTTOM, fill=X)
canvas.configure(yscrollcommand=hscrollbar.set)
canvas.bind('<Configure>', lambda e: canvas.configure(scrollregion=canvas.bbox('all')))
frame = Frame(canvas)
canvas.create_window((0,0), window=frame, anchor='nw')
for i in range(100):
Button(frame, text=f'button {i}').grid(row=i, column=i)
root.mainloop()