Skip to main content
 首页 » 编程设计

具有水平和垂直滚动条的python Tkinter框架

2024年12月31日6yjmyzz

我正在尝试在笔记本中创建一个框架,该框架将使用来自 https://lucasg.github.io/2015/07/21/How-to-make-a-proper-double-scrollbar-frame-in-Tkinter/ 的类代码进行滚动

但是,无论出于何种原因,当我使窗口小于内容区域时(ScheduleMatrix 是一个包含一堆小部件的 ttk.Frame),滚动条会调整大小但仍处于非事件状态且无法使用。我错过了什么?如果有所不同,添加到 ScheduleMatrix Frame 的小部件将使用网格几何管理器进行排列。

class BVSGUI(ttk.Frame): 
    def __init__(self, master): 
        ttk.Frame.__init__(self, master) 
        nb = ttk.Notebook(self) 
        nb.pack(expand=True, fill="both") 
        nb.enable_traversal() 
 
        p1 = ttk.Frame(nb) 
        p1.pack(expand=True, fill="both") 
        nb.add(p1, text='First Tab', underline=0) 
        ds1 = DoubleScrollbarFrame(p1) 
        ds1.pack(expand=True, fill="both") 
        m1 = ScheduleMatrix(ds1.canvas) 
        m1.pack(expand=True, fill="both") 
 
        p23 = ttk.Frame(nb) 
        p23.pack(expand=True, fill="both") 
        nb.add(p23, text='Tab 23', underline=0) 
        ds23 = DoubleScrollbarFrame(p23) 
        ds23.pack(expand=True, fill="both") 
        m23 = ScheduleMatrix(ds23.canvas) 
        m23.pack(expand=True, fill="both") 

请您参考如下方法:

我为您制作了一个可以执行此操作的框架,可用 here .像普通框架一样使用它,而不是像上面那样。像这样:

p1 = DoubleScrolledFrame(nb) 
nb.add(p1, text='First Tab', underline=0) 
m1 = ScheduleMatrix(p1) 
m1.pack(expand=True, fill="both")