How Do I Delete Text Inside Of A Text Box When A User Clicks The Textbox?

27 Views Asked by At

I have created this GUI program in Python using the Tkinter module to learn how to do so:

(https://i.stack.imgur.com/Ey76v.png)

However I would like it if the "Enter username" text would dissapear after you click it just like how it works on piratically every website when you are imputing in your authentication infromation

How would I do this with this code?:

from tkinter import * 


count = 0

def click(): 
    global count 
    count += 1
    print("You have clicked the button "+str(count)+" Times")

def submit():
    Username = Enter_Box.get() 
    print("You have set your username to: "+Username)
    delete()

def delete(): 
    Enter_Box.delete(0,END)

def backspace(): 
    Enter_Box.delete(len(Enter_Box.get())-1,END)

Window = Tk() 

Photo = PhotoImage(file="Pig2.png")

Like_Button = PhotoImage(file="Like-Button2.png")

Window.geometry("900x600")

Window.title("The Ultimate GUI Program")

Window.iconbitmap("AngryBird9.ico")


button = Button(Window,
                text="Click me",
                command=click,
                font=("Comic Sans,",10,"bold"),
                fg="Red",
                bg="black",
                activeforeground="Red",
                activebackground="black",
                image=Like_Button,
                compound="bottom")


button.place(x=50,y=50) 

Window.config(background="white") 

 
Label = Label(Window, 
              text="You are using the best program ever!", 
              font=("Arial",10,"bold"),
              fg="red",
              bg="white",relief=RAISED,bd=10,
              padx=10,
              pady=10,image=Photo,
              compound="bottom")


Label.place(x=170,y=170)  

Enter_Box = Entry(Window,font=("Arial"),fg="Black",bg="Gray") 
Enter_Box.place(x=460,y=220)

Submit_button = Button(Window,text="Submit",command=submit)
Submit_button.place(x=700,y=220)

Delete_button = Button(Window,text="Delete",command=delete)
Delete_button.place(x=750,y=220)

BackSpace_button = Button(Window,text="Backspace",command=backspace)
BackSpace_button.place(x=795,y=220)

Enter_Box.insert(0,"Enter username")

Window.mainloop()

I have tried to search this problem up however all I can find is how to delete the text when a user enters a character and not just when clicked.

0

There are 0 best solutions below