首页 > 解决方案 > 几秒钟后如何删除框架及其标签?

问题描述

我正在制作一个小程序。我制作了一个框架和一个标签,其中包含一些在单击按钮后出现的文本。没关系。现在我想制作一个按钮,上面写着“后退”或“关闭”之类的东西,它关闭了那个框架和它的标签。

我要关闭的内容:
![图片]:https ://imgur.com/a/sO6rYJs

如何照顾我关闭那个框架和它的标签:

![图片]:https ://imgur.com/a/GVVny33

我尝试了一些代码,例如: frame.after(2000, lambda: frame.destroy()) 但它不起作用。我尝试了更多,但又一次..它不起作用。

def inceput():
global windows3
windows3 = Tk()
windows3.title("EasyQuizy v1.0")
windows3.geometry("600x600+600+200")
windows3.resizable(False, False)
windows3.configure(bg="#472025")

headerFrame = Frame(windows3, width=("100"), height=("0")).pack(side=TOP)
frameLeft = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=0, y=0)
frameRight = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=500, y=0)
header = Label(headerFrame, width=("100"), height=("3"), bg="#9d7448", fg="#d9ab33", borderwidth=1, relief="solid",
               font="Helvetica 14 bold italic", text=("Bine ai venit, " + str(numeUtilizator.get()) + '!')).pack()

butonRights = Button(frameLeft, width=("9"), height=("2"), text="Drepturi de \nautor", bg="#6ab891", fg="#131313",
                     font="arial 8 bold", borderwidth=4, relief="raised", command = drepturi_autor)
butonRights.place(x=7, y=100)

butonInfo = Button(frameLeft, width=("9"), height=("2"), text="Imbunatatiri", bg="#6ab891", fg="#131313",
                   font="arial 8 bold", borderwidth=4, relief="raised")
butonInfo.place(x=7, y=180)
windows3.mainloop()





def drepturi_autor():
global frame
frame = Frame(windows3, highlightbackground="black", highlightcolor="black", highlightthickness=2, width=(390), height=(150), bg="#afd5c1").place(x=105, y=90)
label1 = Label(frame,text="EasyQuizy este o aplicatie\ncreata de mine pentru tine.", bg="#82ac96", fg="#f2f2f2", font="arial 14 bold italic").place(x=152, y=102)
frame.after(2000, frame.destroy)

标签: pythontkinter

解决方案


试试看

from tkinter import *

windows3 = Tk()
windows3.title("EasyQuizy v1.0")
windows3.geometry("600x600+600+200")
windows3.resizable(False, False)
windows3.configure(bg="#472025")

def drepturi_autor():
    frame = Frame(windows3, highlightbackground="black", highlightcolor="black", highlightthickness=2, width=(390), height=(150), bg="#afd5c1")
    frame.pack()
    label1 = Label(frame,text="EasyQuizy este o aplicatie\ncreata de mine pentru tine.", bg="#82ac96", fg="#f2f2f2", font="arial 14 bold italic").place(x=100, y=52)
    frame.after(2000, frame.destroy)

headerFrame = Frame(windows3, width=("100"), height=("0")).pack(side=TOP)
frameLeft = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=0, y=0)
frameRight = Frame(windows3, width="100", height="600", bg="#7b8781").place(x=500, y=0)
header = Label(headerFrame, width=("100"), height=("3"), bg="#9d7448", fg="#d9ab33", borderwidth=1, relief="solid",
               font="Helvetica 14 bold italic", text=('Bine ai venit!')).pack()

butonRights = Button(frameLeft, width=("9"), height=("2"), text="Drepturi de \nautor", bg="#6ab891", fg="#131313",
                     font="arial 8 bold", borderwidth=4, relief="raised", command = drepturi_autor)
butonRights.place(x=7, y=100)


windows3.mainloop()

推荐阅读