【问题标题】:setting vertical and horizontal bars to canvas将垂直和水平条设置为画布
【发布时间】:2021-08-06 11:44:03
【问题描述】:

有人可以帮我解决这个问题吗,似乎无法让滚动条工作:(

canvas = Canvas(tab0, bg='red')


frmbtnspecs = ttk.Frame(canvas)
frmbtnspecs.pack(side="top")



lbl = Label(frmbtnspecs, width=8, text="Model:", justify=RIGHT, anchor="e").grid(row=0, column=4, sticky=W, pady=2)
inp_cond_model = Text(frmbtnspecs, height=1, width=35, relief=GROOVE, borderwidth=2)
inp_cond_model.grid(row=0, column=5, sticky=NW, pady=2)

lbl = Label(frmbtnspecs, width=16, text="Version:", justify=RIGHT, anchor="e").grid(row=0, column=6,
                                                                                             sticky=W, pady=2)
inp_cond_firmware = Text(frmbtnspecs, height=1, width=35, relief=GROOVE, borderwidth=2)
inp_cond_firmware.grid(row=0, column=7, sticky=NW, pady=2)

frmbtn = ttk.Frame(canvas)
frmbtn.pack(side="top", expand=1, fill="both")

coll = int(0)
specvar = int(1)


ttk.Button(frmbtn, width="5", text="OK", image=photoOK).grid(column=coll, row=3, padx=1, pady=1)
ttk.Button(frmbtn, width="5", text="Not Ok", image=photoNot).grid(column=coll, row=4, padx=1, pady=1)
lblspec = Label(frmbtn, text=y_respexpt, justify='left', anchor=N)
lblspec.grid(column=coll, row=5, rowspan=55, sticky=N, padx=20, pady=20)


vertibar = Scrollbar(tab0, orient=VERTICAL)
vertibar.pack(side=RIGHT, fill=Y)
vertibar.config(command=canvas.yview)
horibar = Scrollbar(tab0, orient=HORIZONTAL)
horibar.pack(side=BOTTOM, fill=X)
horibar.config(command=canvas.xview)

canvas.pack(expand=True, side=LEFT, fill=BOTH)
canvas.config(xscrollcommand=horibar.set, yscrollcommand=vertibar.set)

滚动条的位置出现但什么都不做enter image description here

【问题讨论】:

    标签: python-3.x scrollbar


    【解决方案1】:
    container = ttk.Frame(root)
    canvas = tk.Canvas(container)
    scrollbar_x = ttk.Scrollbar(container, orient="horizontal", command=canvas.xview)
    scrollbar_y = ttk.Scrollbar(container, orient="vertical", command=canvas.yview)
    scrollable_frame = ttk.Frame(canvas)
    

    ....你的代码(在 scrollable_frame 内)

    container.pack(expand=1, fill="both")
    scrollbar_x.pack(side="bottom", fill="x")
    scrollbar_y.pack(side="right", fill="y")
    canvas.pack(side="bottom", fill="both", expand=True)
    

    【讨论】:

      猜你喜欢
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      • 2011-08-16
      • 2019-10-31
      • 2014-05-04
      • 2014-03-31
      • 2016-05-23
      相关资源
      最近更新 更多