mpenn/scripts/ClosePopup.py

44 lines
1.6 KiB
Python

import customtkinter as Ctk
from icons.icons import Icons
class ClosePopup(Ctk.CTkToplevel):
def __init__(self,master, callback, **kwargs, ):
super().__init__(master, **kwargs)
self.icons = Icons()
self.my_font = Ctk.CTkFont(family="Berlin Sans FB", size=22)
self.geometry("400x300")
self.resizable(False, False)
icon_path = self.icons.get_icon_path()
self.iconbitmap(icon_path)
self.after(201, lambda: self.iconbitmap(icon_path))
self.callback = callback
self.label = Ctk.CTkLabel(self, text="Do you want to leave?\n You might lose some Data", font=self.my_font)
# Add exit button
self.exit_button = Ctk.CTkButton(self, text="Exit",fg_color="#bd202d",hover_color="#f24150", command=self.confirm_exit, font=self.my_font)
# Add leave button
self.leave_button = Ctk.CTkButton(self, text="Stay", command=self.destroy, font=self.my_font)
self.grab_set()
#aligning
self.align()
# Confirm exit method
def confirm_exit(self):
self.destroy() # Closes the ToplevelWindow
self.callback()
def align(self):
self.label.place(
relx=0.5,
rely=0.4,
anchor="center",
)
self.exit_button.place(
relx=0.25,
rely=0.6,
anchor="center",
)
self.leave_button.place(
relx=0.75,
rely=0.6,
anchor="center",
)