使用tkinter完成的一个系统,在删除时出错了

问题遇到的现象和发生背景

使用tkinter完成的一个系统,在删除时出错了

问题相关代码,请勿粘贴截图
def delete():
    print("删除")
    winNew8 = tk.Toplevel()
    winNew8.geometry(align_str)  # 设置窗口大小 和原窗口一致
    winNew8.resizable(width=True, height=True)
    # 设置窗口是否可变长、宽,True:可变,False:不可变
    winNew8.title('删除信息模式')
    label_a = tk.Label(winNew8, text="学生选修课程系统设计", bg="#00BFFF", fg="red", font=("宋体", 30), relief=GROOVE).pack()
    label_b = tk.Label(winNew8, text="---------学生选课系统---------", font=("宋体", 20)).pack()
    # 定义上面的窗口界面
    # 定义下面二种查询方式   通过姓名查询  或者通过课程查询  其他方式没想到
    label_19 = tk.Label(winNew8, text="按学生姓名删除:", font=("宋体", 10))
    label_19.place(relx=0.25, rely=0.3)
    label_20 = tk.Label(winNew8, text="按课程名字删除:", font=("宋体", 10))
    label_20.place(relx=0.25, rely=0.4)
    # 定义二个输入输入框
    inp21 = tk.Entry(winNew8)
    inp21.place(relx=0.45, rely=0.3)  # 学生姓名传值
    inp22 = tk.Entry(winNew8)
    inp22.place(relx=0.45, rely=0.4)  # 学生学号传值
    # 定义二个确定按钮
    btn4 = tk.Button(winNew8, text="确定", command=lambda: namedelete(inp21.get(), inp21, text5))  # 学生姓名确定
    btn4.place(relx=0.75, rely=0.28)
    btn5 = tk.Button(winNew8, text="确定", command=lambda: classdelete(inp22.get(), inp22, text5))  # 课程姓名确定
    btn5.place(relx=0.75, rely=0.39)
    # 写一个备注ps
    ps = tk.Label(winNew8, text="PS:若文本框未显出信息,则该学生选课信息未成功保存,请重试!", font=("宋体", 10))
    ps.place(relx=0, rely=0.52)
    # 定义一个关闭按钮
    btClose4 = tk.Button(winNew8, text='关闭', command=winNew8.destroy)  # 取消按钮
    btClose4.place(relx=0.75, rely=0.5)
    # 定义下面的文本框
    text5 = tk.Text(winNew8, bg="#d3fbfb")
    text5.place(rely=0.6)

def classdelete(i22, inp22, text5):  # 按照课程号来删除,
    print(i22)  # 检验传值是否成功
    with open("D://课程//课程信息.txt", "r") as ff:  # 遍历这个txt把
        for i in ff:
            if i22:
                if str(i22) in i:
                    i = str(i);
                    #print(i) #课程编号:1    课程名称:1    课程性质:1    任课老师:1    课程学分:1    开课时间:1
                    #text5.get(1.0,tk.END)
                    text5.delete(i+".0",tk.END)
                    #text5.delete("1.0",END)
                    inp22.delete(1, tk.END)

运行结果及报错内容

in delete
self.tk.call(self._w, 'delete', index1, index2)
_tkinter.TclError: bad text index "课程编号:1课程名称:1课程性质:1任课老师:1课程学分:1开课时间:1
.0"

我的解答思路和尝试过的方法

不知道怎么解决

我想要达到的结果

能解决删除问题

应该是文件的问题,把txt内容附出来

也不知道你的逻辑是什么,但是错误内容是第45行的初始位置标识错误。也就是报错里的index1参数。

文本框delete方法的第一个参数应该是一个位置坐标,而你给定的是"课程编号:1课程名称:1课程性质:1任课老师:1课程学分:1开课时间:1.0"。应当是"1.0"

目前得到的信息只能说明哪里错误,其它变量我也不知道是什么含义。

这篇文章:Tkinter使用教程(一) 也许能够解决你的问题,你可以看下