Python Forum
[Tkinter] Scrollbar, Frame and size of Frame
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Scrollbar, Frame and size of Frame
#1
Hello everybody.
I use this script and it works good.
But, i don't know how to do Frame(body) more bigger by vertically.
Could somebody help me? Rolleyes Rolleyes Rolleyes

import tkinter as tk
from tkinter import ttk
from tkinter import *

class Scrollable(tk.Frame):
    """
       Make a frame scrollable with scrollbar on the right.
       After adding or removing widgets to the scrollable frame, 
       call the update() method to refresh the scrollable area.
    """

    def __init__(self, frame, width=16):

        scrollbar = tk.Scrollbar(frame, width=width)
        scrollbar.pack(side=tk.RIGHT, fill=tk.Y)#, expand=False)

        self.canvas = tk.Canvas(frame, yscrollcommand=scrollbar.set)
        self.canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

        scrollbar.config(command=self.canvas.yview)

        self.canvas.bind('<Configure>', self.__fill_canvas)

        # base class initialization
        tk.Frame.__init__(self, frame)         

        # assign this obj (the inner frame) to the windows item of the canvas
        self.windows_item = self.canvas.create_window(0,0, window=self, anchor=tk.NW)


    def __fill_canvas(self, event):
        "Enlarge the windows item to the canvas width"

        canvas_width = event.width
        self.canvas.itemconfig(self.windows_item, width = canvas_width)        

    def update(self):
        "Update the canvas and the scrollregion"

        self.update_idletasks()
        self.canvas.config(scrollregion=self.canvas.bbox(self.windows_item))


root = tk.Tk()

root.geometry('1000x700+100+50')
root.resizable('False','False')
header = Frame(root)
body = Frame(root)
footer = Frame(root)
header.pack()
body.pack(fill='x')
footer.pack()
header.configure(width=200, height=100)


l1=Label(header, text="The header")
l1.grid(column=0,row=0)
ttk.Label(footer, text="The Footer").pack()


scrollable_body = Scrollable(body, width=32)

for i in range(30):
    ttk.Button(scrollable_body, text="I'm a button in the scrollable frame").grid(column=0,row=i)
    ttk.Button(scrollable_body, text="I'm").grid(column=1,row=i)

scrollable_body.update()

root.mainloop()
Reply


Messages In This Thread
Scrollbar, Frame and size of Frame - by Maksim - Sep-27-2019, 07:55 AM
RE: Scrollbar, Frame and size of Frame - by Larz60+ - Sep-27-2019, 04:10 PM
RE: Scrollbar, Frame and size of Frame - by Maksim - Sep-30-2019, 07:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Horizontal extension of widgets + frame size adapted to content Fab117 3 500 Feb-22-2024, 06:54 PM
Last Post: deanhystad
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 1,022 Jan-16-2024, 06:44 PM
Last Post: rob101
  Problem passing argument to functionin inTkinter frame ericwm7248 3 1,029 Sep-11-2023, 03:11 PM
Last Post: deanhystad
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,596 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,549 Aug-07-2023, 02:59 PM
Last Post: deanhystad
  tkinter mapview in a frame janeik 2 1,337 Jun-22-2023, 02:53 PM
Last Post: deanhystad
  [Tkinter] Image in Frame in Tabbed Widget Columbo 4 2,162 Sep-28-2022, 08:04 PM
Last Post: deanhystad
  [Tkinter] Frame with treeview virencm 5 7,029 Feb-01-2022, 04:58 PM
Last Post: deanhystad
  [Tkinter] Scrollbar apffal 7 3,153 Oct-11-2021, 08:26 PM
Last Post: deanhystad
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,147 Sep-30-2021, 05:57 PM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020