Tkinter - 带滚动条的列表框

时间:2017-06-07 14:24:37

标签: python-3.x tkinter listbox

在我的代码中,我想在Listbox小部件中添加一些小部件,以便稍后我可以在其上使用滚动条。这里的问题是,无论我放入多少小部件,列表框都将继续扩展,并且滚动条不可用,因为它不会更新。我该如何解决这个问题?

from tkinter import *    

def pr_deleteChart():
    global _plotDictionary

    #_F_delChart.iconbitmap('ContaParole_icona.ico')

    _F_mainUpper = Frame(_root)
    _F_mainUpper.grid(row = 0, column = 0, padx = 5, pady = 5, sticky = "nsew")

    _F_mainLower = Frame(_root)
    _F_mainLower.grid(row = 1, column = 0, padx = 5, sticky = "sew")

    #listbox scrollbar
    _S_ListBoxScrollBar = Scrollbar(_F_mainUpper,orient = "vertical")
    _S_ListBoxScrollBar.grid(row = 1, column = 1, sticky = "nse")

    #Main listbox
    _L_mainListBox = Listbox(_F_mainUpper)
    _L_mainListBox.grid(row = 1, column = 0, sticky = "nsew")

    _S_ListBoxScrollBar.config(command = _L_mainListBox.yview)

    #Carico lista di chiavi
    keysList = list(_graphReferences.keys())

    #Per ogni grafico salvo variabile, checkButton e salvo tutto dentro _plotDictionary
    for index in range(0,len(keysList)):

        button = Checkbutton(_L_mainListBox, text = keysList[index])
        button.grid(row = index, column = 0, sticky = "nw")

if __name__== "__main__":

    _root = Tk()
    _root.title("Main window")
    _root.resizable(width = FALSE, height = FALSE)

    _graphReferences = {"1":"2","3":"4","5":"6","7":"8","9":"10","11":"12"}

    pr_deleteChart()

1 个答案:

答案 0 :(得分:0)

您无法使用gridpackplace滚动添加到列表框的项目。与列表框关联的滚动条仅使用列表框的insert方法滚动添加到列表框的项目。