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"))
        canv.config(highlightthickness=0)
        sbar.config(command=canv.yview)                   
        canv.config(yscrollcommand=sbar.set)             
        sbar.pack(side=RIGHT, fill=Y)                     
        canv.pack(side=LEFT, expand=YES, fill=BOTH)
        self.create_widgets(canv)       

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

        Button(canv,
               text = "Search",
               command = self.tell_story
               ).pack()



    def callback(self, line):
        line = str(line)
        soft = re.sub("b'", "", line).split(' ', 1)[0]
        url = "https://packages.debian.org/jessie/" + soft
        webbrowser.open_new_tab(url)



    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]
        process
        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))
            link.pack()


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

Re: Tkinter Scrollbar not scrolling

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

Hello,

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

OK,

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?

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


Return to GUI

Who is online

Users browsing this forum: No registered users and 6 guests