Search code examples
pythonpython-3.xtkintercustomtkinter

I want to get the text from this variable using customtkinter


I want to get the text from this, How do I get it? I've instaled tkniter, customtkinter but idk how to get the text from this

entry1=customtkinter.CTkEntry(master=frame, width=220, placeholder_text='Username')


Solution

  • This link will take you to customtkinter documentation. Navigate to CTk Entry in CTk Widgets, one of the methods of CTkEntry is .get() which returns the string in the entry field.

    This is the code to access the value of the entered fields Username and Password.

    import customtkinter
    
    customtkinter.set_appearance_mode("System")
    customtkinter.set_default_color_theme("blue")
    
    
    root = customtkinter.CTk()
    root.title("app")
    root.geometry("500x350")
    
    
    def login():
       username = entry1.get()
       password = entry2.get()
       print(username)
       print(password)
    
    
    frame = customtkinter.CTkFrame(master=root)
    frame.pack(pady=20, padx=60, fill="both", expand=True)
    
    
    label = customtkinter.CTkLabel(master=frame, text="Login System", 
    font=("Roboto",24))
    label.pack(pady=12,padx=10)
    
    
    entry1 = customtkinter.CTkEntry(master=frame, 
    placeholder_text="Username")
    entry1.pack(pady=12,padx=10)
    
    
    entry2 = customtkinter.CTkEntry(master=frame, 
    placeholder_text="Password", show="*")
    entry2.pack(pady=12,padx=10)
    
    
    button = customtkinter.CTkButton(master=frame,text="Login", 
    command=login, fg_color = "blue")
    button.pack(pady=12,padx=10)
    
    
    root.mainloop()