in Education by
I would like to clear the written email and write password grid when a del button is pressed, and then I can still save new emails and passwords, how do I do this? I tried to create a def clear using grid_slaves, but it erases everything, I want it to delete just write an email and write a password from tkinter import * roots = Tk() roots.title("Email's save") roots.geometry("500x500") e = Entry(roots) e.grid(row=0, column=1) e.focus_set() p = Entry(roots, show="*") p.grid(row=1, column=1) p.focus_set() textEmail = StringVar() textPassword = StringVar() def callback(): textEmail.set(textEmail.get() + e.get() + "\n") textPassword.set(textPassword.get() + p.get() + "\n") def EmailPassword(): email = Label(roots, text="Email: ",font=('Courier', 14)) email.grid(row=0, sticky=W) passoword = Label(roots, text="Password: ",font=('Courier', 14)) passoword.grid(row=1, sticky=W) saved_email = Label(roots, text="Saved Email",font=('Courier', 14)) saved_email.grid(row=15, column=0) saved_password = Label(roots, text="Password",font=('Courier', 14)) saved_password.grid(row=15, column=15) write_email = Label(roots, textvariable=textEmail,font=('Courier', 14)) write_email.grid(row=20, column=0) write_password = Label(roots, textvariable=textPassword,font=('Courier', 14)) write_password.grid(row=20, column=15) btn_save = Button(roots, text="Save", command= callback) btn_save.grid(row=10, column=2, sticky=W) btn_del = Button(roots, text="X", fg="red") btn_del.grid(row=60, column= 20) roots.mainloop() EmailPassword() Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
The grid is just a single text field with newlines. To clear it, just set the text value to "". Try this code. from tkinter import * roots = Tk() roots.title("Email's save") roots.geometry("500x500") e = Entry(roots) e.grid(row=0, column=1) e.focus_set() p = Entry(roots, show="*") p.grid(row=1, column=1) p.focus_set() textEmail = StringVar() textPassword = StringVar() def callback(): textEmail.set(textEmail.get() + e.get() + "\n") textPassword.set(textPassword.get() + p.get() + "\n") def clearentries(): e.delete(0, 'end') p.delete(0, 'end') def cleargrid(): textEmail.set("") textPassword.set("") def EmailPassword(): print ('save') global lstlabels email = Label(roots, text="Email: ",font=('Courier', 14)) email.grid(row=0, sticky=W) passoword = Label(roots, text="Password: ",font=('Courier', 14)) passoword.grid(row=1, sticky=W) saved_email = Label(roots, text="Saved Email",font=('Courier', 14)) saved_email.grid(row=15, column=0) saved_password = Label(roots, text="Password",font=('Courier', 14)) saved_password.grid(row=15, column=15) write_email = Label(roots, textvariable=textEmail,font=('Courier', 14)) write_email.grid(row=20, column=0) write_password = Label(roots, textvariable=textPassword,font=('Courier', 14)) write_password.grid(row=20, column=15) btn_save = Button(roots, text="Save", command= callback) btn_save.grid(row=10, column=2, sticky=W) btn_del = Button(roots, text="X", fg="red", command= cleargrid) # reset grid btn_del.grid(row=60, column= 20) roots.mainloop() def key(event): # listen for key press if event.keysym == 'Delete': clearentries() # clear text boxes roots.bind_all('', key) EmailPassword() If you are a beginner and want to know more about Python the do check out the python for data science course

Related questions

0 votes
    I need to find a way to clear the Listbox for the refresh function which I am making. The function should ... clearing the Listbox) Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me how do I start learning Python for Data Science? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I am new to python, I have this code: # columns are [0]title [1]year [2]rating [3]length(min) [4]genre ... make that int into a list? Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Do I need coding skills for Data Science using Python? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    I used the pyhton: for m in regex.findall(r"\X", 'ल्लील्ली', regex.UNICODE): for i in m: print(i, i.encode(' ... कृ','प','या','ल्ली' Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    please see my code below, example_list = [ ['a','b','c'], ['f','g','h'], ['i','j','k'], ] my_string = ''' ' ... g','h'), ('i','j','k'); Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    webbrowser.open('https://api.WhatsApp.com/send?phone=number') I want to send WhatsApp messages to numbers without ... in this link. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    The code works fine but the only problem I encountered an error is: bad operand type for unary +: 'str'. This is ... for unary +: 'str' Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    It is a principal question, regarding the theory of neural networks: Why do we have to normalize the input for ... is not normalized? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Do the Data Science course requires Python learning in-depth? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    In the python documentation, an instance of a named_tuple is created by using the below code: Point = named_tuple(' ... of doing it? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    Here's the code: ''' file_path = (r'C:\Users\Luka\Desktop\Pyhton exercises\pi_digits.txt') with open( ... file_object: print(line) Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what should I learn in Python for Data Science? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
0 votes
    Should I learn R or Python for Data Science? Select the correct answer from above options...
asked Jan 17, 2022 in Education by JackTerrance
...