mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-06-01 22:00:53 +00:00
Scripts
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import tkinter as tk
|
||||
|
||||
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, **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.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((4, 4), 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"))
|
||||
Reference in New Issue
Block a user