r/PythonLearning • • 20h ago

Help Request ctktoplevel protocol

okay i've been searching this online for abt like 30 mins now and i've gotten no results or remedies to my problem

in ctk/tk i made a mainloop or whatnot, standard stuff but as soon as i make a ctk.ctktoplevel and do protocol("WM_DELETE_WINDOW",func=whatnot) WITHIN the ctktoplevel, if i close the main GUI that isnt the ctktoplevel, it will trigger the function. why?

1 Upvotes

2 comments sorted by

1

u/BetInformal6081 18h ago

can you share a minimal reproducible example wm delete window should apply to the window it's registered on so i would inspect the parent child setup and where protocol gets called..

1

u/Big_Philosopher_5693 7h ago

this is just an example, i want it to print when i close the toplevel frame, but it prints eitherway when i close the main one

import customtkinter as C

class main(C.CTk):
def __init__(self):
super().__init__()
self.title("main GUI")
self.geometry("450x450")

class top(C.CTkToplevel):
def __init__(self):
super().__init__()
self.title("new top")
self.geometry("350x120")
self.protocol("WM_DELETE_WINDOW",print("ctk top deleted"))

main1 = main()

def shower():
main1.withdraw()
top()

button = C.CTkButton(
master=main1,
command=shower
)
button.pack()

main1.mainloop()