python 向下滚动时按钮被切断

jv4diomz  于 2023-04-04  发布在  Python
关注(0)|答案(1)|浏览(104)

我正在尝试创建文件资源管理器,当文件夹加载大量内容时,按钮会被切断。似乎按钮在那里,但没有显示。我该如何解决这个问题?

class User_interface(tk.Frame):
    """A friendly little module"""
    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        self.photo = ImageTk.PhotoImage(Image.open(r"path").resize((100, 150)))
        self.back_png = ImageTk.PhotoImage(Image.open(r"path"))
        self.canvas = tk.Canvas(self, borderwidth=0, background="#ffffff")
        self.frame = tk.Frame(self, background="#ffffff")
        self.scroll_bar = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
        self.canvas.configure(yscrollcommand=self.scroll_bar.set)

        self.scroll_bar.pack(side="right", fill="y")
        self.canvas.pack(side="left", fill=tk.BOTH, expand=True)
        self.canvas.create_window((0, 0), window=self.frame, anchor="nw",
                                  tags="self.frame")
   
        self.frame.bind("<Configure>", self.onFrameConfigure)
        self.bind_all("<MouseWheel>", self.on_mousewheel)

        for i in range(self.frame.grid_size()[0]):
            self.frame.columnconfigure(i, weight=1)

        #3000 items in folder
        for index in range(len(folder)):
            button = ttk.Button(self.frame, text=f'{folder[index]["name"]}',
                                image=self.photo,
                                compound=TOP,
                                command=lambda name=folder[index]:
                                self.select_folder(name))

            button.grid(row=1 + int(math.floor(index / 5)),
                        column=index % 5, padx=5, pady=5, sticky='ew')

    def onFrameConfigure(self, event):
        """Reset the scroll region to encompass the inner frame"""
        self.canvas.configure(scrollregion=self.canvas.bbox("all")

screenshot of folders being cut off
我期望能够向下滚动并看到所有的文件。我试着改变按钮被分配到的位置。

相关问题