0

我正在开发一个具有内置文件管理器的项目,我希望每个文件 (a Button) 都有自己的行,但我无法Button填充整行。

我试着把它Button粘到 W+E 上,但没有用

def reloadWindow(self):
   for x in self.widgets:
        x.grid_forget()
    self.widgets = []
    for path, subdirs, files in os.walk(dir):
        for name in files:
            if not name == "":
                replacer = self.proDir + "\\assets"
                self.helloBTN = Button(self, text=path.replace(str(replacer), "") + "\\" + name)
                self.helloBTN.grid(row=len(self.widgets), sticky=W+E)
                self.widgets.append(self.helloBTN)

实际结果如下所示:

在此处输入图像描述

但是,我希望Button填充整个窗口(代码是从顶级类执行的)。

编辑:这是一个完整的窗口剪辑链接链接

EDIT2:一个链接到一个精简版的代码。在第 41 行,请将 [DIR] 替换为真实目录(最多 36 个文件)。

4

0 回答 0