tkinter how to make frame scrollable

  python, scrollbar, tkinter, tkinter-layout

I’ve been using this framework Switch between two frames in tkinter for developing an app… I’m kinda new to tkinter and I just finished developing a beta version and I just noticed that these frames are not native scrollable. I checked some tutorials online (about creating canvas inside or using ScrolledFrame package…). So I tried with scrolled frame package but it doesn’t work right (like a normal app should): basically the content doesn’t resize with the interface. So is here anyone kind to help me and improve the basic structure of the framework in the link to make frames scrollables?
Here’s how I managed to create it scrollable but loosing resizing capabilities:

try:
    import tkinter as tk                # python 3
    from tkinter import font as tkfont  # python 3
    from tkscrolledframe import ScrolledFrame
except ImportError:
    import Tkinter as tk     # python 2
    import tkFont as tkfont  # python 2


class SampleApp(tk.Tk):

def __init__(self, *args, **kwargs):
    tk.Tk.__init__(self, *args, **kwargs)

    self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")

    #Crate scrollable
    scrollable = ScrolledFrame(self, width=1600, height=900)
    scrollable.pack(side="top", expand=1, fill="both")
    scrollable.grid_rowconfigure(0, weight=1)
    scrollable.grid_columnconfigure(0, weight=1)
    #scrollable.grid_propagate(True)

    #
    scrollable.bind_arrow_keys(self)
    scrollable.bind_scroll_wheel(self)

    #Creo il container dentro scrollable: come se creassi un container dentro ad un container
    container = scrollable.display_widget(tk.Frame) 

    self.frames = {}
    for F in (StartPage, PageOne, PageTwo):
        page_name = F.__name__
        frame = F(parent=container, controller=self)
        self.frames[page_name] = frame

        # put all of the pages in the same location;
        # the one on the top of the stacking order
        # will be the one that is visible.
        frame.grid(row=0, column=0, sticky="nsew")

    self.show_frame("StartPage")
 #rest of the app...

Source: Python Questions

LEAVE A COMMENT