所以我在这里搜索过的线程尝试了很多不同的解决方案。这是我的代码:
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()
以下是我使用的所有可能与此问题有关的软件包:
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
我尝试过设置滚动条和画布,并以许多不同的顺序填充画布。我试过给画布特定的滚动区域。我似乎无法让滚动条工作。
谢谢!
答案 0 :(得分:1)
解决了它。我不得不添加
sticky = NE + SE
作为
的论据yscrollbar.grid()
并将滚动条放在保持滚动滚动的列左侧的列中。
我认为滚动条始终存在,但网格几何管理器将其放置在我无法访问的位置。