Python tkinter grid_forget()

时间:2013-09-30 15:28:38

标签: python python-2.7 tkinter

我想让标签显示并消失,但我遇到grid_forget()的问题。这是代码的一部分:

def creabackuno():
    showinfo( "Wait..","I am creating the backup, please wait...")
    vsl=Label(gui,text="Working, please wait...",font=("arial",16)).grid(row=20,rowspan=1,column=0,columnspan=1,padx=10,sticky=N)
    try:
        copytree(path,r"backup\dirbackup1\.minecraft")
        showinfo( "OK!","Backup (1) created!")
        vsl.grid_forget()
    except OSError:
        showerror( "Nope!","There is already a backup to restore")
        vsl.grid_forget()

这是控制台的错误:

AttributeError: 'NoneType' object has no attribute 'grid_forget'

1 个答案:

答案 0 :(得分:3)

您目前vsl等于grid Label方法的返回值。此外,此方法始终返回None(因此,您的错误中为NoneType)。使你的代码像这样:

vsl=Label(gui,text="Working, please wait...",font=("arial",16))
vsl.grid(row=20,rowspan=1,column=0,columnspan=1,padx=10,sticky=N)

现在vsl指向标签,而不是grid方法的返回值,即None