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

Not possible to write into CTkEntry after CTkMessagebox is closed #60

Open
SandraHeinzova opened this issue Apr 12, 2024 · 17 comments
Open
Labels
bug Something isn't working

Comments

@SandraHeinzova
Copy link

Hello.
I'm using CTkMessagebox to show that user entered wrong format of date. Everything works fine until I close the CTkMessagebox with warning (by button and also the X on left top corner). After that, I have to wait several seconds (almost minutes) to be able to enter date again - and it's not very user friendly .
Is there anything I overlooked?
Thank you for any ideas!
Sandra

@Akascape
Copy link
Owner

Akascape commented Apr 12, 2024

@SandraHeinzova Can you please provide an example? How are you using the warning messagebox?

@SandraHeinzova
Copy link
Author

@Akascape Hi, thanks for reply.
I have this function

def validate_date(date):
    min_date_possible = datetime(1958, 8, 4)
    max_date_possible = datetime.now()
    try:
        entered_date = datetime.strptime(date, "%Y-%m-%d")
        if min_date_possible <= entered_date <= max_date_possible:
            return True
        else:
            raise ValueError
    except ValueError:
        CTkMessagebox(title="Warning", message="Wrong date. The date has to be in format of YYYY-MM-DD. OR between 1958-08-04 and present.", icon="warning")
        return False

and date comes from this Entry

date_entry = ct.CTkEntry(app, placeholder_text="YYYY-MM-DD", justify="center", width=200, height=50)
date_entry.pack()

@Akascape
Copy link
Owner

Did you try the .get() method? It makes the window to wait before any button press on the messagebox.

@SandraHeinzova
Copy link
Author

@Akascape Yes, I am using date_entry.get() method, to get entered value

@Akascape
Copy link
Owner

Akascape commented Apr 12, 2024

@SandraHeinzova I mean there is also a .get() method in the messagebox. Like in this example:

msg = CTkMessagebox(title="Warning Message!", message="Waning!",
                  icon="warning")
    
response = msg.get()

@SandraHeinzova
Copy link
Author

@Akascape I tried to add

response = msg.get()
if response == "Close":
   msg.destroy()

but there is no change.. the Messagebox open correctly, but when I press the button Close, I cannot use any of CTkEntry's I have.. I have to wait for some long time, or open secondary TopLevel window and close it afterwards to be able enter values into CTkEntry 🤔

@Akascape
Copy link
Owner

@SandraHeinzova Ok I will check this soon. For now you can use the normal tkinter messagebox. I will try to provide a fix in next update.

@SandraHeinzova
Copy link
Author

@Akascape thank you for your help

@Akascape
Copy link
Owner

Akascape commented Apr 17, 2024

@SandraHeinzova Can you please test this example and tell if this issue is happening with this example:

import customtkinter
from CTkMessagebox import CTkMessagebox

root = customtkinter.CTk()

CTkMessagebox()
entry = customtkinter.CTkEntry(master=root)
entry.pack(padx=10, pady=10)

root.mainloop()

@SandraHeinzova
Copy link
Author

@Akascape yes, the issue is still happening.
I quite solved it with this

CTkMessagebox(app_ct, message="Wrong date")
app_ct.after(10000,  date_entry.focus_force)

but is hard to estimate amount of milliseconds 🤔 also focus() and focus_set() didnt work, only focus_force() did work

@Akascape
Copy link
Owner

@SandraHeinzova Ok, I am not facing this issue with the messagebox and entries, so I don't know why it is showing this behaviour in your system. But it's good that we can solve it with the force_focus method.

@SandraHeinzova
Copy link
Author

@Akascape I am glad it's not some common issue, it's really weird it's not working properly on my system. But thank you for your effort

@resnbl
Copy link

resnbl commented May 21, 2024

I have also run into the same issue. I tried your sample app above and it "appeared" to work, but then I went and clicked on the main window while the messagebox was still open (just to test modality), and from that point on, dismissing the messagebox did not allow access to your Entry box.

In my app, checkboxes and buttons on my main window continued to operate after the messagebox was dismissed.

I did find the force_focus() workaround effective, although it seems I only need a 1,000ms delay, not 10,000.

Tested on:
macOS-13.6.6-x86_64-i386-64bit
Python 3.12.2
Tk/Tcl 8.6.14
customtkinter 5.2.2
CTkMessagebox 2.5

@Ryanjju
Copy link

Ryanjju commented Jun 2, 2024

Yes I have also faced this issue under macOS 14.2.1 with python 3.12.
Maybe because the two windows and a wrong focus, but the weird thing is, that the CTkOptionMenu still works and after I switch to an other window, and back to my python application the entry works.

I now use the workaround with focus_force

@Akascape Akascape added the bug Something isn't working label Jun 2, 2024
@PedroxionX
Copy link

I also have the same issue, if someone finds a solution please post it 🙏 .

@Ryanjju
Copy link

Ryanjju commented Oct 4, 2024

I've found a solution. I will send it later this day, if I found the snippet.

@Ryanjju
Copy link

Ryanjju commented Oct 7, 2024

After some searching. I've found the workaround again.

CTkMessagebox.CTkMessagebox(title="Invalid input", message="Please enter a valid number for epochs.", option_1="OK", icon="warning") 
self.after(100, self.epochs_entry.focus_force) 
return

You need to set the focus, and then it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants