Tkinter Scrollbar not scrolling

Post here if you need help with creating a Graphical User Interface in Python.

Tkinter Scrollbar not scrolling

Postby jtmtnman » Tue Sep 27, 2016 8:25 am

If someone would be so kind to look at my little program, and tell me everything I'm doing wrong, I would appreciate it. This is my first attempt at using objects, so I'm a little thrown off. My main issue is that the scrollbar isn't scrolling. Sorry to put things vague. Thanks.

Code: Select all
from tkinter import *
import subprocess, re, webbrowser

class Application(Frame):
    def __init__(self, master):
        super(Application, self).__init__(master) 
        self.pack(expand=YES, fill=BOTH)
        #There must be a way to have canv, and sbar NOT be be global.
        global canv
        canv = Canvas(self)
        global sbar
        sbar = Scrollbar(self)
        canv.config(width=400, height=600)               
        canv.config(scrollregion = canv.bbox("all"))
        sbar.pack(side=RIGHT, fill=Y)                     
        canv.pack(side=LEFT, expand=YES, fill=BOTH)

    def create_widgets(self, canv):
        x = Label(canv,text = "Repository Search: ")
        self.person_ent = Entry(canv)

               text = "Search",
               command = self.tell_story

    def callback(self, line):
        line = str(line)
        soft = re.sub("b'", "", line).split(' ', 1)[0]
        url = "" + soft

    def tell_story(self):
        person = self.person_ent.get()
        bashCommand = "apt-cache search " + person
        process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
        output = process.communicate()[0]
        for line in output.splitlines():
            link = Label(canv, text=line, foreground="#0000ff", cursor="hand1")
            link.bind('<Button-1>', lambda event, line = line: self.callback(line))

root = Tk()
root.title("Apt Repository Search")
app = Application(root)
Last edited by Yoriz on Tue Sep 27, 2016 11:46 am, edited 1 time in total.
Reason: First post lock.
Posts: 1
Joined: Tue Sep 27, 2016 7:26 am

Re: Tkinter Scrollbar not scrolling

Postby Larz60+ » Wed Sep 28, 2016 3:27 am


First, please be aware the forum will be moving in 3 days to The site is active now, and you may want to register and re-post.


A Scrollbar may appear to not work if there is nothing to scroll through.

you can eliminate the global if you add self. to canv (when referencing it in methods, use the same name self.canv)
Outside of the class, it can be referred to as yourclassname.canv

try filling your scroll-able area and see if it starts working.

Again, if you re-post on the new forum, you'll be sure to get a lot more advice.

If it still doesn't work, I'll take a closer look.

One question, Is there a reason why you are using a Canvas widget vs a Text widget?

Posts: 1307
Joined: Thu Apr 03, 2014 4:06 pm

Return to GUI

Who is online

Users browsing this forum: No registered users and 4 guests