Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.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 在运行另一个查询函数之前,清除窗口中的数据_Python_Tkinter_Treeview_Ttk - Fatal编程技术网

Python 在运行另一个查询函数之前,清除窗口中的数据

Python 在运行另一个查询函数之前,清除窗口中的数据,python,tkinter,treeview,ttk,Python,Tkinter,Treeview,Ttk,我有一个GUI连接到数据库,我需要显示一些数据 def学生部: 树[列]=名称、DOB、部门名称 tree.column0,宽度=100 tree.columnName,宽度=100 tree.columnDOB,宽度=100 tree.column部门名称,宽度=100 tree.heading0,text=Panther ID tree.headingName,text=Name tree.headingDOB,text=出生年份 tree.headingDepartment\u name,

我有一个GUI连接到数据库,我需要显示一些数据

def学生部: 树[列]=名称、DOB、部门名称 tree.column0,宽度=100 tree.columnName,宽度=100 tree.columnDOB,宽度=100 tree.column部门名称,宽度=100 tree.heading0,text=Panther ID tree.headingName,text=Name tree.headingDOB,text=出生年份 tree.headingDepartment\u name,text=部门名称 sql=从学生中选择* cursor.executesql 结果=cursor.fetchall 对于范围为0的i,结果: tree.insert,i,text=strresult[i][0],values=strresult[i][1],strresult[i][2],strresult[i][3] def讲师信息: 树[列]=名称、部门\u ID tree.column0,宽度=100 tree.columnName,宽度=100 tree.column部门ID,宽度=100 tree.heading0,text=讲师ID tree.headingName,text=Name tree.headingDepartment\u ID,text=部门ID sql=从讲师中选择* cursor.executesql 结果=cursor.fetchall 对于范围为0的i,结果: tree.insert,i,text=strresult[i][0],values=strresult[i][1],strresult[i][2] 我有两个按钮连接到这两个功能

btn1=tk.Buttonroot,text=Student Department,command=Student\u Department.pack btn2=tk.Buttonroot,text=讲师信息,command=讲师信息包
两个作品都找到了,但当我点击1个按钮,然后点击2个按钮时,窗口中仍然有数据。当我点击按钮时,数据会被添加到显示中,但之前的数据不会被清除。如何在单击按钮并显示新数据时清除数据。

我确信答案应该是修改那些在插入新数据之前进行搜索的方法,确保字段或显示是清晰的,这样就可以了

尝试查看是否可以找到名为.clear的方法。在插入新数据之前使用它