Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback function #65

Open
WindupYT opened this issue Jul 21, 2024 · 1 comment
Open

Callback function #65

WindupYT opened this issue Jul 21, 2024 · 1 comment

Comments

@WindupYT
Copy link

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,

@revel111
Copy link

revel111 commented Sep 17, 2024

@WindupYT Hello. Have you found any elegant workaround by any chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants