import tkinter as tk color_yellow = "#FFFFD9" color_light_green = "#D6F6D6" color_dark_green = "#008080" color_orange = "#FFDDCC" color_grey = "#D0D0D0" color_red = "#ff4d4d" color_white = "#FFFFFF" color_black = "#000000" initial_bk_file = '''#BUSINESS=Example Business #CURRENCY=Rs. #CURRENCY_FORMAT=ind #NAME=Example User Name ''' def string_to_int(val): try: return int(val) except ValueError: return 0 def format_currency(amount, _type, currency): c = "" a = abs(amount) if _type == "ind": s, *d = str(a).partition(".") r = ",".join([s[x - 2:x] for x in range(-3, -len(s), -2)][::-1] + [s[-3:]]) c = currency + ("".join([r] + d)) else: c = currency + ("{:,}".format(a)) if amount < 0: c = "(" + c + ")" return c class Modal: TYPE_ALERT = 1 TYPE_QUESTION = 2 def __init__(self, parent, message, modal_type): self.type = modal_type self.positive_method = None self.negative_method = None # modal self.modal = tk.Frame(parent, background=color_orange, height=200, width=200, highlightbackground=color_red, highlightthickness=1) self.modal.place(x=0, rely=1, anchor='sw') tk.Label(self.modal, text=message, bg=self.modal["background"], font="arial 12 normal", wraplength=200).place(relx=0.5, rely=0.3, anchor='center') self.modal.focus() self.modal.bind("", lambda event: self.positive_method()) self.modal.bind("", lambda event: self.cancel_modal()) self.modal.bind("", lambda event: 'break') if self.type == Modal.TYPE_ALERT: tk.Button(self.modal, text="Okay", background=self.modal["background"], border=0, font="arial 12 bold", command=lambda: self.positive_method()).place(relx=0.5, rely=0.9, anchor='center') elif self.type == Modal.TYPE_QUESTION: tk.Button(self.modal, text="Yes", background=self.modal["background"], border=0, font="arial 12 bold", command=lambda: self.positive_method()).place(relx=0.1, rely=0.9, anchor='sw') tk.Button(self.modal, text="No", background=self.modal["background"], border=0, font="arial 12 bold", command=lambda: self.negative_method()).place(relx=0.9, rely=0.9, anchor='se') def destroy(self): for widget in self.modal.winfo_children(): widget.destroy() self.modal.destroy() def cancel_modal(self): if self.type == Modal.TYPE_QUESTION: self.negative_method() else: self.positive_method() def set_positive(self, method): self.positive_method = method def set_negative(self, method): self.negative_method = method