【问题标题】:Adding a scroll bar to a canvas向画布添加滚动条
【发布时间】:2019-02-12 12:03:32
【问题描述】:

我正在尝试使用 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)

当画布中有很多标签时,我只需要滚动条能够垂直滚动

【问题讨论】:

    标签: tkinter tkinter-canvas


    【解决方案1】:

    画布只能滚动使用create_window 方法添加的项目。它不会滚动通过packplacegrid 添加的项目。

    【讨论】:

      猜你喜欢
      • 2019-06-04
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-09
      • 2013-10-23
      • 1970-01-01
      相关资源
      最近更新 更多