Search code examples
pythoncustomtkinter

how to clear a textbox in Python after button is pressed?


I'm starting in python and I have created this app to open a website after you write it in a textbox, but don't know how to clear it after the button is pressed, please help me...

Code:

import customtkinter

import webbrowser

customtkinter.set_appearance_mode("system")

customtkinter.set_default_color_theme("dark-blue")

root = customtkinter.CTk()
root.geometry("500x350")

def login():

       url = entry1.get()

       webbrowser.open(url)

frame = customtkinter.CTkFrame(master=root)
frame.pack(pady=20, padx=20, fill="both", expand="True")

label = customtkinter.CTkLabel(master=frame, text="enter website")
label.pack(pady=12, padx=10)

entry1 = customtkinter.CTkEntry(master=frame, placeholder_text="website")
entry1.pack(pady=12, padx=10)

button = customtkinter.CTkButton(master=frame, text="Enviar", command=login)
button.pack(pady=12, padx=10)

root.mainloop()

Solution

  • Since you are not using textvariable property you can use delete() method of the widget:

    entry1.delete(0, len(entry1.get()))
    

    Find the documentation here or here