I am trying to create a custom tkinter program. For a week or so I've been struggling with the messagebox and the interactions between it and the main window. This is the following code:
def check_entries(self):
if self.api_key_entry.get().strip() != "" and self.api_key_entry.get().strip() != "API Key" and \
self.api_secret_entry.get().strip() !="" and self.api_secret_entry.get().strip() !="API Secret":
self.api_hashed_key = self.hasher.hash(self.api_key_entry.get().replace(' ',''))
self.secret_hashed_key = self.hasher.hash(self.api_secret_entry.get().replace(' ', ''))
self.store_the_keys()
else:
self.msg = CTkMessagebox(
title="Error",
message="Please fill in both keys",
justify="center",
font=("Anita Semi-square", 20),
icon="cancel",
option_1="OK"
)
self.msg_x = (self.parent.winfo_rootx()) + int(self.msg.width/2)
self.msg_y = (self.parent.winfo_rooty()) + int(self.msg.height)
self.msg.geometry(f'+{self.msg_x}+{self.msg_y}')
self.msg.wait_window()
When the CTkMessagebox appears I can't interact with the main window which is what I want. The problem comes when I click on the messagebox or move it (I can also move the main window and the same happens). Then even though it haven't closed the messagebox I can interact with the main window and I want to able to interact with it only when the messagebox is closed.
I tried different approaches like:
self.msg.wait_window()
while self.msg.get() != "OK":
self.grab_set()
self.grab_release()
But this didn't seem to work as well. Then I tried implementing the messagebox from tkinter and used showinfo:
self.grab_set()
messagebox.showinfo(message="need keys")
self.grab_release()
But as before when I clicked on the main window the messagebox minimized and I could once again interact with the main window.
Can anyone suggest any other solutions. The self that I use in the code is a frame the I've appended to the main app and the CTkMessagebox is a custom widget on github: https://github.com/Akascape/CTkMessagebox
Thanks in advance.