SHB11
SHB11

Reputation: 375

Tkinter Scrollbar not showing

So I've tried a bunch of different solutions from threads I've searched here. Here is my code:

def begin():

    global path, thumbPath, fullImgPath, running
    root = Tkinter.Tk()
    root.title("keyBuilder")

    frame = Frame(root, width = 630, height = 450)
    frame.pack()

    exitButton = Button(frame, text="Exit keyBuilder", width=10, command=exitProgram)
    exitButton.grid(row = 0, column = 0)

    Running = True
    b = Button(frame, text="Set Directory Path", width=20, command=getPath)
    b.grid(row = 0, column = 1)

    groupMenu = Frame(frame, width = 150)
    tree = Treeview(groupMenu, selectmode = 'browse')
    tree.pack(fill = Y)
    tree.insert(parent = '', index = 'end', text = 'Master')
    a = tree.insert(parent = '', index = 'end', text = 'Group 1')
    tree.insert(parent = a, index = 'end', text = 'Slide 1')

    yscrollbar = Tkinter.Scrollbar(frame, orient = VERTICAL)
    numImages = 0
    for infile in glob.glob(os.path.join(path + '/imgThumb/', '*jpg')):
        numImages += 1
    COLUMNS = 4
    image_count = 0

    gallery = Canvas(frame, width = COLUMNS * THUMB_SIZE, height = COLUMNS * THUMB_SIZE, yscrollcommand = yscrollbar.set)#
    yscrollbar.config(command = gallery.yview)
    for infile in glob.glob(os.path.join(path + '/imgThumb/', '*.jpg')):
        print "filling gallery with: " + infile
        image_count += 1
        r, c = divmod(image_count-1, COLUMNS)
        im = Image.open(infile)
        tkimage = ImageTk.PhotoImage(im)
        myvar = Label(gallery, image=tkimage)
        myvar.image = tkimage
        gallery.create_window(c*THUMB_SIZE, r*THUMB_SIZE, anchor = NW, window = myvar)
    gallery.config(scrollregion=gallery.bbox(ALL))
    yscrollbar.config(command = gallery.yview)
    groupMenu.grid(row = 1, column = 0)
    gallery.grid(row = 1, column = 1)
    yscrollbar.grid(row = 1, column = 2)
    yscrollbar.config(command = gallery.yview)
    root.mainloop()

and here are all of the packages I'm using which might have something to do with the issue:

import pymongo
import glob, os
from subprocess import Popen
import Tkinter
from Tkinter import *
from ttk import *
from PIL import Image, ImageTk
import zipfile
import shutil

I've tried setting up the scrollbar and the canvas, and populating the canvas in many different orders. I've tried giving the canvas specific scroll regions. I just can't seem to get the scrollbar to work.

Thanks!

Upvotes: 0

Views: 3488

Answers (1)

SHB11
SHB11

Reputation: 375

Solved it. I had to add

sticky = NE + SE

as an argument to

yscrollbar.grid()

and place the scroll bar in a column one to the left of the column holding the canvas being scrolled.

I think the scrollbar was always there but the grid geometry manager placed it somewhere that I couldn't access.

Upvotes: 1

Related Questions