Python tkinter 滚动条:是否可以通过单击箭头 1 或箭头 2 来设置要移动的像素数?

问题描述 投票:0回答:1

我正在使用类 ScrollbarFrame(tk.Frame) 来显示表格并希望表格移动 1 行,单击向上按钮(箭头 1)或向下按钮(箭头 2)。每行的高度为 21 个像素。目前的转变是 ca。 28 像素。

我发现,每次单击箭头按钮都会滚动 1 个单位。但是,我没有找到任何单位设置或任何其他更改滚动长度的设置。 谢谢你的帮助!

这是我的课:

class ScrollbarFrame(tk.Frame):
"""
Extends class tk.Frame to support a scrollable Frame 
This class is independent from the widgets to be scrolled and 
can be used to replace a standard tk.Frame
"""
def __init__(self, parent, width=0, height=0, **kwargs):
    tk.Frame.__init__(self, parent, **kwargs)

    # The Scrollbar, layout to the right
    vsb = tk.Scrollbar(self, orient="vertical")
    vsb.pack(side="right", fill="y")

    # The Canvas which supports the Scrollbar Interface, layout to the left
    self.canvas = tk.Canvas(self, borderwidth=0, background="#ffffff")
    self.canvas.configure(width=width, height=height)

    self.canvas.pack(side="left", fill="both", expand=True)

    # Bind the Scrollbar to the self.canvas Scrollbar Interface
    self.canvas.configure(yscrollcommand=vsb.set)
    vsb.configure(command=self.canvas.yview)

    # The Frame to be scrolled, layout into the canvas
    # All widgets to be scrolled have to use this Frame as parent
    self.scrolled_frame = tk.Frame(self.canvas, background=self.canvas.cget('bg'))
    
    self.canvas.create_window((0, 0), window=self.scrolled_frame, anchor="nw")

    # Configures the scrollregion of the Canvas dynamically
    self.scrolled_frame.bind("<Configure>", self.on_configure)

def on_configure(self, event):
    """Set the scroll region to encompass the scrolled frame"""
    self.canvas.configure(scrollregion=self.canvas.bbox("all"))
python-3.x tkinter scrollbar
1个回答
0
投票

假设您的

ScrollbarFrame
使用画布来滚动框架,您可以使用
yscrollincrement
选项在画布上设置单位大小。

© www.soinside.com 2019 - 2024. All rights reserved.