CTkMessagebox icon indicating copy to clipboard operation
CTkMessagebox copied to clipboard

Not possible to write into CTkEntry after CTkMessagebox is closed

Open SandraHeinzova opened this issue 1 year ago • 17 comments

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 avatar Apr 12 '24 12:04 SandraHeinzova

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

Akascape avatar Apr 12 '24 13:04 Akascape

@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()

SandraHeinzova avatar Apr 12 '24 14:04 SandraHeinzova

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

Akascape avatar Apr 12 '24 14:04 Akascape

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

SandraHeinzova avatar Apr 12 '24 15:04 SandraHeinzova

@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 avatar Apr 12 '24 15:04 Akascape

@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 avatar Apr 12 '24 15:04 SandraHeinzova

@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 avatar Apr 12 '24 15:04 Akascape

@Akascape thank you for your help

SandraHeinzova avatar Apr 13 '24 11:04 SandraHeinzova

@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 avatar Apr 17 '24 10:04 Akascape

@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 avatar Apr 24 '24 15:04 SandraHeinzova

@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 avatar Apr 24 '24 15:04 Akascape

@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

SandraHeinzova avatar Apr 25 '24 05:04 SandraHeinzova

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

resnbl avatar May 21 '24 21:05 resnbl

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

Ryanjju avatar Jun 02 '24 15:06 Ryanjju

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

PedroxionX avatar Oct 04 '24 05:10 PedroxionX

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

Ryanjju avatar Oct 04 '24 07:10 Ryanjju

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.

Ryanjju avatar Oct 07 '24 07:10 Ryanjju