0

在构建一个检查按钮列表(3,000 个案例)时,该列表被切断。

这是一个小样本:

import tkinter as tk

class Example(tk.Frame):
    def __init__(self, parent):

        tk.Frame.__init__(self, parent)
        self.canvas = tk.Canvas(self, borderwidth=0, background="#ffffff")
        self.frame = tk.Frame(self.canvas, background="#ffffff")
        self.vsb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
        self.canvas.configure(yscrollcommand=self.vsb.set)

        self.vsb.pack(side="right", fill="y")
        self.canvas.pack(side="left", fill="both", expand=True)
        self.canvas.create_window((4,4), window=self.frame, anchor="nw",
                                  tags="self.frame")

        self.frame.bind("<Configure>", self.onFrameConfigure)

        self.populate()

    def populate(self):

        for row in range(3000):

            t="Example -Checkbutton %s" %row
            button = tk.Checkbutton(self.frame, padx=7, relief=tk.RIDGE, text=t,                                    
                                onvalue=1, offvalue=0,  font='Courier 12')
            button.grid(row=row, column=1, sticky='news')
            
    def onFrameConfigure(self, event):
        self.canvas.configure(scrollregion=self.canvas.bbox("all"))

if __name__ == "__main__":
    root=tk.Tk()
    example = Example(root)
    example.pack(side="top", fill="both", expand=True)
    root.mainloop()

程序的输出:

| | 示例清单 0


| | 示例清单 1123


| | 示例清单 1126


| | 示例清单 1125



| | 示例清单 2999

不显示示例清单 1126 - 2998,并且示例清单 2999 由双线指示。

是否有显示完整列表的参数?

4

0 回答 0