我正在尝试使用tkinter将滚动条添加到画布上,但是我正在运行的代码未创建可用的滚动条。有什么错误吗?
这是代码:
proofscreen.title("Proof")
proofscreen.geometry("800x800")
proofscreen.configure(background="white")
# add scrollbar
frame = Frame(proofscreen)
frame.grid()
canvas = Canvas(frame, bg="white")
vbar = Scrollbar(frame)
vbar.grid(row=0, column=1)
vbar.config(command=canvas.yview)
canvas.update()
canvas.config(yscrollcommand=vbar.set)
canvas.grid(row=0, column=0)
frame.grid_columnconfigure((0, 1), weight=1)
proofscreen.grid_columnconfigure((0), weight=1)
frame.grid_rowconfigure((0), weight=1)
proofscreen.grid_rowconfigure((0), weight=1)
Label(canvas, text="Proof", font=("Calibri", 16), bg="white", fg="black").pack(anchor=W)
Label(canvas, text="", bg="white", fg="black").pack(anchor=W)
Label(canvas, text="Deduction", font=("Calibri", 14), bg="white", fg="black").pack(anchor=W)
当画布中有很多标签时,我只需要滚动条即可垂直滚动
答案 0 :(得分:1)
画布只能滚动使用create_window
方法添加的项目。它不会滚动通过pack
,place
或grid
添加的项目。