我正在使用 Tkinter 制作用户输入表单,并在单击提交按钮时从用户那里获取值并将值存储在数据库中。单击提交按钮后,我想清除条目小部件中的所有字段,以便将值存储在数据库中,同时清除条目小部件,以便用户可以再次填写详细信息。我尝试了 delete(0;'end') 命令,但它没有用。以下是我的代码:def database(): customer_name = name.get() mobile_no = num.get() email_id = mail_id.get() address = addr.get() result = { "Customer Name":customer_name, "Mobile":mobile_no, "Email ID":email_id, "Address":address } print(result) db.Customer_Info.insert_one(result) print('Value Inserted') client.close()##Creating tkinter windowdef main_page(): global window window = Tk() window.title('Products') window.geometry('400x500') global name,uname,mob,num,mail_id,addr name = StringVar() num = IntVar() num.set('') mail_id = StringVar() addr = StringVar() Label(window,text = 'HN Organics',background = 'green', foreground = 'white',font = ('Arial',20)).grid(column = 0, row = 0, padx = 120, pady =25) Label(window ,text = "Name").grid() uname = Entry(window,textvariable = name).grid() Label(window ,text = "Mobile No.").grid() mob = Entry(window,textvariable = num).grid() Label(window ,text = "Email ID").grid() mail = Entry(window,textvariable = mail_id).grid() Label(window ,text = "Address").grid() addr1 = Entry(window,textvariable = addr).grid() Button(window,text = 'Submit',command = database).grid() window.mainloop()main_page()单击提交按钮时,值存储在数据库中,但我希望条目在存储在数据库中后也能清除。我怎么做??我尝试使用 name.delete(0.'end') / name.delete(0.'END') 甚至 name.delete(0.'Tkinter.END') 但它表明没有属性删除。
添加回答
举报
0/150
提交
取消