简体   繁体   English

Python tkinter grid_forget()

[英]Python tkinter grid_forget()

I want to make a label appear and disappear, but I am having a problem with grid_forget() .我想让标签出现和消失,但我遇到了grid_forget()问题。 This is part of the code:这是代码的一部分:

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()

And this is the error of the console:这是控制台的错误:

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

You currently have vsl equal to the return value of the grid method of Label .您当前的vsl等于Labelgrid方法的返回值。 Furthermore, this method always returns None (hence, the NoneType in your error).此外,此方法始终返回None (因此,您的错误中为 NoneType )。 Make your code like this:让你的代码像这样:

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

Now vsl points to the label, not the return value of the grid method, which is None .现在vsl指向标签,而不是grid方法的返回值,即None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM