in Education by
I'm currently developing my first python program, a booking system using tkinter. I have a customer account creation screen that uses a number of Entry boxes. When the Entry box is clicked the following key bind is called to clear the entry box of its instruction (ie. "enter name") def entry_click(event): if "enter" in event.widget.get(): event.widget.delete(0, "end") event.widget.insert(0, "") event.widget.configure(fg="white") #example Entry fields new_name = Entry(root) new_name.insert(0, "enter name") new_name.bind('', entry_click) new_name.bind('', entry_focusout) new_email = Entry(root) new_email.insert(0, "enter email") new_email.bind('', entry_click) new_email.bind('', entry_focusout) In a similar vein I'm looking for a way to create a universal event where the appropriate text for that unique entry field is returned to its initial state (ie. "enter first name" or "enter email") if the box is empty when clicked away from. def entry_focusout(): if not event.widget.get(): event.widget.insert(fg="grey") event.widget.insert(0, #[appropriate text here]) How would I be able to do this? Many thanks. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Just add an arg to your entry_focusout event and bind to the Entry widgets with a lambda function. from tkinter import * root = Tk() def entry_click(event): if event.widget["foreground"] == "grey": event.widget.delete(0, "end") event.widget.insert(0, "") event.widget.configure(fg="black") def entry_focusout(event, msg): if not event.widget.get(): event.widget.configure(fg="grey") #you had a typo here event.widget.insert(0, msg) new_name = Entry(root,fg="grey") new_name.insert(0, "enter name") new_name.bind('', entry_click) new_name.bind('', lambda e: entry_focusout(e, "enter name")) new_email = Entry(root,fg="grey") new_email.insert(0, "enter email") new_email.bind('', entry_click) new_email.bind('', lambda e: entry_focusout(e, "enter email")) new_name.pack() new_email.pack() root.mainloop()

Related questions

0 votes
    What is the Git command to blow away all the changes in a file in the working area, since the previous commit? A. ... git log filename C. git checkout filename D. git rm filename...
asked Dec 21, 2022 in Technology by JackTerrance
0 votes
    I have a set of oil wells compiled in the panda's data frame. It looks like this: wells = pd.DataFrame({'date ... -01-01 FIELDZ 10.8 Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I am getting an 'access is denied' error when I attempt to delete a folder that is not empty. I used the ... that is not empty? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I'm starting from the pandas DataFrame docs here: http://pandas.pydata.org/pandas-docs/stable/dsintro.html I'd ... =1)] print valdict Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    suppose I have passed : list=[] How can I check if a list is empty or not? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    import pandas as pd from itertools import combinations, product, permutations MH_P= ["Maria Herrera"] OP_P= ["Oscar ... i solve it? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    In the code below, in "parse" function I am trying to get substring from the string "line". I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    In the code below, in "parse" function I am trying to get substring from the string "line". I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    I'm working with ASP.NET 3.5. I have a list box that users must add items to (I've written ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    There are three boxes in a table. One of the box contains Gold and the other two are empty. A printed message contains in ... Gold is in the Second box'. Which box has the Gold?...
asked Feb 10, 2021 in Education by JackTerrance
0 votes
    Selecting the victim to be rollbacked to the previous state is determined by the minimum cost. The factors ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    If an transaction is performed in a database and committed, the changes are taken to the previous state ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    R square value close to zero indicates a good fit. State if it is true or false? (1)True (2)False...
asked Aug 17, 2021 by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I have a UITableView of customers where a row/customer is selected. The user can then push another view ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
...