tkinter滚动条灰显了

时间:2016-08-26 14:57:04

标签: python tkinter scrollbar

我为滚动条编写了这段代码:

from tkinter import *

from tkinter.ttk import *


root =  Tk()
root.geometry("500x500")

eventFrame = LabelFrame(root, text = "Upcoming Events", width = 500, height = 500)
eventFrame.pack(pady = 5, padx = 5, anchor = CENTER, fill = BOTH, expand = True)

scrollCanvas = Canvas(eventFrame, width = 50, height = 500)
scrollCanvas.pack(pady = 5, padx = 5)

scrollbar = Scrollbar(scrollCanvas)
scrollbar.pack(side = RIGHT, fill = Y)

eventCanvas = Canvas(scrollCanvas, width = 500, height = 500, yscrollcommand = scrollbar.set)
eventCanvas.pack(pady = 5, padx = 5)

for x in range(100):
    label = LabelFrame(eventCanvas, text = "Title {}".format(x), height = 500, width = 500)
    label.pack(pady = 10, padx = 10, expand = True, fill =  BOTH)

    text = Label(label, text = "This is a test event. no.{}".format(x))
    text.pack(anchor = CENTER, pady = 5, padx = 5, expand = True, fill =  BOTH)

scrollbar.config(command = eventCanvas.yview, scrollregion = eventCanvas.bbox("all"))

root.mainloop()

但是,滚动条显示为灰色。我假设,根据其他SO SE的答案,我的酒吧滚动错误的画布。我该如何解决这个问题?我不知道如何在不搞乱的情况下切换画布。

0 个答案:

没有答案