Skip to content

Callback function  #65

@WindupYT

Description

@WindupYT

Hi,

I was wondering if there was a "on_messagebox_close" built-in callback method that I could use. If not, could you please implement one or assist me with this issue?

This is due to the previously reported problem in which you cannot type into CTkEntry after CTkMessageBox has been closed. I am aware of the solution involving root.after(f"{number_of_ms}", f"{entry}".focus_force()). However, using the {number_of_ms} is quite inefficient for me, as the user may take longer / shorter to read based on their abilities, causing the programme to either shift its focus before the reader has finished reading, or in a delayed manner if the reader has finished reading the message way beforehand.

For context, here is a short snippet of my code:

# Username
username_entry = ctk.CTkEntry(master=frame, width=220, placeholder_text="Username", corner_radius=10)
username_entry.place(relx=0.5, y=110, anchor=ctk.CENTER)

# Password 
password_entry = ctk.CTkEntry(master=frame, width=220, placeholder_text="Password", show='*', corner_radius=10)
password_entry.place(relx=0.5, y=165, anchor=ctk.CENTER)

confirm_password_entry = ctk.CTkEntry(master=frame, width=220, placeholder_text="Confirm Password", show='*', corner_radius=10)
confirm_password_entry.place(relx=0.5, y=220, anchor=ctk.CENTER)

password = password_entry.get()
message1 = "Passwords do not match!"
message2 = "Passwords do match!"

def validate_passwords():
    password = password_entry.get()
    confirm_password = confirm_password_entry.get()

    if confirm_password != password:
        # Display the error message box
        message_box = CTkMessagebox(title="Error", message=message1, icon="cancel", option_1="Retry")
        root.after(5000, confirm_password_entry.focus_force)
    else:
        # Display the success message box
        message_box1 = CTkMessagebox(title="Well done", message=message2, icon="check", option_1="Thanks")
        root.after(5000, confirm_password_entry.focus_force)

confirm_password_button = ctk.CTkButton(
    master=frame,
    text="Validate",
    command=validate_passwords,
    corner_radius=10,
    width=40,
    height=27,
)
confirm_password_button.place(relx=0.5, x=125, y=208)

Therefore, I was planning on using the f"{entry}".focus_force straight after the CTkMessageBox has been closed, rather than after a set amount of seconds.

Best regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions