Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法调用destroy命令_Python_Python 2.7_Global Variables - Fatal编程技术网

Python 无法调用destroy命令

Python 无法调用destroy命令,python,python-2.7,global-variables,Python,Python 2.7,Global Variables,我试图关闭一个网格,然后打开一个名为旧网格的新网格,这样我就可以使用一个函数多次执行此操作 testgrid=a_nice_grid def sth(button): if button=='filter': testgrid.destroy() global testgrid testgrid=app_grid.addGrid(name,data) 使用此代码,我得到以下错误: 文件appJar\ap

我试图关闭一个网格,然后打开一个名为旧网格的新网格,这样我就可以使用一个函数多次执行此操作

testgrid=a_nice_grid
def sth(button):
        if button=='filter':

            testgrid.destroy()
            global testgrid
            testgrid=app_grid.addGrid(name,data) 
使用此代码,我得到以下错误:

文件appJar\appJar.py,第2724行,在 返回lambda:funcNameparam 文件,第251行,在某物中 testgrid.destroy 文件C:\Users\User\Anaconda2\lib\lib tk\Tkinter.py,第2097行,在>销毁中 self.tk.叫“毁灭”,self Tcl错误:无法调用销毁命令:应用程序已被销毁

如何以与代码类似的方式为变量testgrid赋予新值

destroy命令将完全删除小部件,并且无法重复使用

您可以简单地使用testgrid.grid\u来代替添加和删除小部件。这将从用户界面中删除小部件,以后可以使用。如果您不希望打开小部件,可以按如下方式运行命令:

testgrid.grid_forget()
testgrid.destroy()

要干净地删除网格,可以使用app.removeGrid

请看这里:

然后,添加另一个栅格时,它可以具有相同的名称:

def press(button):
   app.removeGrid("g")
   app.addGrid("g", [["a", "b", "c"]], 0, 0)

app = gui()
app.addGrid("g", [["a", "b", "c"]])
app.addButton("PRESS", press)
app.go()
注意。当您添加另一个小部件时,您需要指定网格位置,否则它将添加到按钮下方