如何在tkinter中删除框架中的某些标签?

时间:2018-12-03 15:02:26

标签: python tkinter grid frame

我有一个方法可以在单击按钮时显示图像,我希望另一个按钮可以在单击时清除这些图像。 我可以清除整个框架,但是我需要知道如何仅清除某些行和列。

def displayImages():

COLUMNS = 5
image_count = 5

path = ("<my path?\\Images")

for dirName, subdirList, fileList, in os.walk(path):
    if os.path.isdir(path):
        for item in subdirList:
            if os.path.isdir(os.path.join(path,item)):
                for file in os.listdir(os.path.join(path,item)):
                    full_file_path = os.path.join(path, item, file)
                    if file.endswith((".jpg")):
                        image_count+=1
                        r, c = divmod(image_count-1, COLUMNS)
                        global image
                        image = Image.open(full_file_path)
                        image = image.resize((28,28), Image.ANTIALIAS)
                        image = ImageTk.PhotoImage(image)
                        global panel
                        panel = Label(leftFrame, image = image)
                        panel.image=image
                        panel.grid(row=r, column=c)

def hideImages():
for label in leftFrame.grid_slaves():
    if label (is in these rows and columns??):
        label.grid_forget()

0 个答案:

没有答案
相关问题