Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:46:41+00:00 2026-06-13T23:46:41+00:00

Possible Duplicate: Adding a scrollbar to a grid of widgets in Tkinter On my

  • 0

Possible Duplicate:
Adding a scrollbar to a grid of widgets in Tkinter

On my project, i want do display my results in a window, using Tkinter as GUI. I place them in a kind of table, using the grid widget, and the window is separated in two different parts (for different results). But after longer runs, the number of results displayed exceed the height of my screen, so i want to add a scrollbar to my program. I already looked into several questions here on stackoverflow, and the answer that has come closest was this:

Adding a scrollbar to a group of widgets in Tkinter
(just to let You know what I am axactly looking for!)

I am not able to apply that to my program though, maybe because I am rather new to Python and sometimes think i am a Dr. Frankenstein with tutorial-examples.

I tried a lot now, but i cant get the tables to be displayed in the canvas, possibly just some little thing i am missing.

I created an abstract example of my program (without scrollbar) so You know what I am working with, maybe someone of You can help my getting that scrollbar where it belongs!

Thank You very much!

example code: (runs)

import Tkinter as tk
toprow=1
botrow=1
class ProgramWindow(tk.Frame): 

    def __init__(self,name): 
        self.name = name
        tk.Frame.__init__(self,root)
        self.pack()

        if name=="BotWin":
            tk.Label(self,text="FirstColBot",width=30).grid(row=0,column=0)            
            tk.Label(self,text="SecndColBot",width=20).grid(row=0,column=1)

        elif name=="TopWin":
            tk.Label(self,text="FirstColTop",width=30).grid(row=0,column=0)         
            tk.Label(self,text="SecndColTop",width=20).grid(row=0,column=1)

    def addrowTop(self,stuff,otherstuff):
        global toprow

        textfield = tk.Text(self,width=30,height=1)
        textfield.grid(row=toprow,column=0)
        textfield.insert('0.0',stuff)

        textfield = tk.Text(self,width=20,height=1)
        textfield.grid(row=toprow,column=1)
        textfield.insert('0.0',otherstuff)

        toprow+=1

    def addrowBot(self,stuff,otherstuff):
        global botrow

        textfield = tk.Text(self,width=30,height=1)
        textfield.grid(row=botrow,column=0)
        textfield.insert('0.0',stuff)

        textfield = tk.Text(self,width=20,height=1)
        textfield.grid(row=botrow,column=1)
        textfield.insert('0.0',otherstuff)

        botrow+=1

def SomeProg():
    for i in range(20):
        if i%2==0:
            stuff = "Stuff is "+str(i)
            otherstuff=i*3
            Wins[0].addrowTop(stuff,otherstuff)
        elif i%2==1:
            stuff = "Stuff is "+str(i)
            otherstuff=i*4
            Wins[1].addrowBot(stuff,otherstuff)


root = tk.Tk()
root.title("Stuff")

Wins = [ ProgramWindow("TopWin"),ProgramWindow("BotWin")]
SomeProg()

root.mainloop()

additional code with my tries to add the scrollbar (based on example shown in link above).
if the scrollbar is only shown in the lower part, that would be okay since thats the part with the many results.)

import Tkinter as tk
toprow=1
botrow=1
class ProgramWindow(tk.Frame): 

    def __init__(self,name): 
        self.name = name
        self.frame=tk.Frame.__init__(self,root)


        if name=="BotWin":
            tk.Label(self,text="FirstColBot",width=30).grid(row=0,column=0)            
            tk.Label(self,text="SecndColBot",width=20).grid(row=0,column=1)

            self.canvas = tk.Canvas(root, borderwidth=0, background="#ffffff")
            self.vsb = tk.Scrollbar(root, orient="vertical", command=self.canvas.yview)
            self.canvas.configure(yscrollcommand=self.vsb.set)

            self.vsb.pack(side="right", fill="y")
            self.canvas.pack(side="left", fill="both", expand=True)
            self.canvas.create_window((4,4), window=self.frame)

            self.bind("<Configure>", self.OnFrameConfigure)

        elif name=="TopWin":
            self.pack()
            tk.Label(self,text="FirstColTop",width=30).grid(row=0,column=0)         
            tk.Label(self,text="SecndColTop",width=20).grid(row=0,column=1)

    def addrowTop(self,stuff,otherstuff):
        global toprow

        textfield = tk.Text(self,width=30,height=1)
        textfield.grid(row=toprow,column=0)
        textfield.insert('0.0',stuff)

        textfield = tk.Text(self,width=20,height=1)
        textfield.grid(row=toprow,column=1)
        textfield.insert('0.0',otherstuff)

        toprow+=1

    def OnFrameConfigure(self, event):
        self.canvas.configure(scrollregion=self.frame.bbox("all"))

    def addrowBot(self,stuff,otherstuff):
        global botrow

        textfield = tk.Text(self,width=30,height=1)
        textfield.grid(row=botrow,column=0)
        textfield.insert('0.0',stuff)

        textfield = tk.Text(self,width=20,height=1)
        textfield.grid(row=botrow,column=1)
        textfield.insert('0.0',otherstuff)

        botrow+=1

def SomeProg():
    for i in range(20):
        if i%2==0:
            stuff = "Stuff is "+str(i)
            otherstuff=i*3
            Wins[0].addrowTop(stuff,otherstuff)
        elif i%2==1:
            stuff = "Stuff is "+str(i)
            otherstuff=i*4
            Wins[1].addrowBot(stuff,otherstuff)


root = tk.Tk()
root.title("Stuff")

Wins = [ ProgramWindow("TopWin"),ProgramWindow("BotWin")]
SomeProg()

root.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:46:42+00:00Added an answer on June 13, 2026 at 11:46 pm

    To adapt Bryan Oakley’s answer to your specific problem:

    • create your frame with the canvas as parent
    • use the canvas as the parameter of scrollregion

    Note: when subclassing in python, you do not need to store the result of parent __init__ since it operate on self.

    Here is the patch:

         def __init__(self,name): 
             self.name = name
    -        self.frame=tk.Frame.__init__(self,root)
    
             if name=="BotWin":
    +            self.canvas = tk.Canvas(root, borderwidth=0, background="#ffffff")
    +            tk.Frame.__init__(self,self.canvas)
                 tk.Label(self,text="FirstColBot",width=30).grid(row=0,column=0)            
                 tk.Label(self,text="SecndColBot",width=20).grid(row=0,column=1)
    -            self.canvas = tk.Canvas(root, borderwidth=0, background="#ffffff")
                 self.vsb = tk.Scrollbar(root, orient="vertical", command=self.canvas.yview)
                 self.canvas.configure(yscrollcommand=self.vsb.set)
    
                 self.vsb.pack(side="right", fill="y")
                 self.canvas.pack(side="left", fill="both", expand=True)
    -            self.canvas.create_window((4,4), window=self.frame)
    +            self.canvas.create_window((4,4), window=self)
                 self.bind("<Configure>", self.OnFrameConfigure)
    
             elif name=="TopWin":
    +            self.frame=tk.Frame.__init__(self,root)
                 self.pack()
                 tk.Label(self,text="FirstColTop",width=30).grid(row=0,column=0)         
                 tk.Label(self,text="SecndColTop",width=20).grid(row=0,column=1)
    @@ -41,7 +40,7 @@
             toprow+=1
    
         def OnFrameConfigure(self, event):
    -        self.canvas.configure(scrollregion=self.frame.bbox("all"))
    +        self.canvas.configure(scrollregion=self.canvas.bbox("all"))
    
         def addrowBot(self,stuff,otherstuff):
             global botrow
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: adding media element in windows phone 7? I Want Details Explanation and
Possible Duplicate: Adding additional data to select options using jQuery Is there a way
Possible Duplicate: Adding Core Data to existing iPhone project how can I add core
Possible Duplicate: How to display row numbers in a ListView? Currently I am using
Possible Duplicate: Adding HTML entities using CSS content I have the following setup CSS:
Possible Duplicate: adding images to UItableView I want to add image in UITableView in
Possible Duplicate: Adding label and text box control to GUI Can someone help me
Possible Duplicate: IE7 display issues (adding extra top margin) So I have the following
Possible Duplicate: Adding members to an existing object Lets say you have the following
Possible Duplicate: Adding a guideline to the editor in Visual Studio Is there a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.