Tkinter Frame未销毁/更新

2024-09-30 22:26:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过删除一个旧的框架来更新一个框架,并在网格中添加一个新的框架。我可以将新的框架添加到网格中,但是旧框架似乎没有删除,因此新框架和旧框架被放置在彼此的顶部,看起来很凌乱。我该怎么解决这个问题呢?下面是我代码的基本要点。在

def buttonGet(frame, root, top):
    frame.destroy()
    bottomFrame = Frame(root)
    bottomFrame.grid(row=1, column=0)
    #Adding things to Bottom Frame

def mainForecast(root):


    topFrame = Frame(root)
    topFrame.grid(row=0, column=0)
    bottomFrame = Frame(root)
    bottomFrame.grid(row=1, column=0)

    #Lables, Buttons, Entries within each frame


    label1 = Label(topFrame, font=TruckingFont, text="label1")
    label1.grid(row=1, column=2, rowspan=4, columnspan=2)

    button1 = Button(topFrame, text="Retrieve Current Information", width=45, command=lambda: buttonGet(bottomFrame, root, topFrame))
    button1.grid(row=5, column=0, columnspan=2)



    root.mainloop()

Tags: text框架网格defcolumnrootframegrid