Not possible to write into CTkEntry after CTkMessagebox is closed
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
@SandraHeinzova Can you please provide an example? How are you using the warning messagebox?
@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()
Did you try the .get() method? It makes the window to wait before any button press on the messagebox.
@Akascape Yes, I am using date_entry.get() method, to get entered value
@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()
@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 🤔
@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.
@Akascape thank you for your help
@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()
@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
@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.
@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
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
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
I also have the same issue, if someone finds a solution please post it 🙏 .
I've found a solution. I will send it later this day, if I found the snippet.
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.