# salary calculator
from customtkinter import *
from Settings import Settings
class App:
def __init__(self):
self.exit_btn = None
self.theme_button = None
self.root = None
self.tk = None
self.tabs = None
self.tab1 = None
self.tab2 = None
self.tab3 = None
self.tab4 = None
self.pb = None
self.p = None
self.sb = None
self.salary_lbl_frame = None
self.salary_input = None
self.month = 0
self.day = self.month // 30
self.year = self.month * 12
self.week = self.day * 7
self.send_res = None
self.year_res = None
self.month_res = None
self.week_res = None
self.day_res = None
self.res1 = f"monthly salary is\t{self.month}"
self.res2 = f"yearly salary is\t{self.year}"
self.res3 = f"weekly salary is\t{self.week}"
self.res4 = f"daily salary is\t{self.day}"
self.results = None
self.res_control = True
self.label = True
self.set = Settings()
self.check_theme_lbl = None
self.error = None
self.iserror = False
self.deside = None
self.info = None
self.radio_var = None
self.radiobutton_day = None
self.radiobutton_week = None
self.radiobutton_year = None
self.radiobutton_month = None
def notebook_code(self):
# setup Notebook
self.tabs = CTkTabview(self.tk)
self.tabs.add('Input')
self.tabs.add('Output')
self.tabs.add("Settings")
self.tabs.add("About me")
self.tabs.set('Input')
self.tab1 = CTkFrame(self.tabs.tab('Input'), height=1000, width=1000)
self.tab2 = CTkFrame(self.tabs.tab('Output'), height=1000, width=1000)
self.tab3 = CTkFrame(self.tabs.tab('Settings'), height=1000, width=1000)
self.tab4 = CTkFrame(self.tabs.tab('About me'), height=1000, width=1000)
self.tab1.pack(fill=BOTH)
self.tab2.pack(fill=BOTH)
self.tab3.pack(fill=BOTH)
self.tab4.pack(fill=BOTH)
def widgets(self):
# title
title = CTkLabel(
self.tk,
text='$alary calculator',
width=999,
bg_color='black',
text_color='white'
)
title.place(rely=0.035, relx=0.5, anchor=CENTER)
# Notebook widgets
self.tabs.pack(pady=20, fill=BOTH, expand=True)
# first tab
self.salary_lbl_frame = CTkFrame(self.tab1, fg_color='grey20')
self.salary_input = CTkEntry(self.salary_lbl_frame)
self.send_res = CTkButton(
self.salary_lbl_frame,
text="send",
command=self.send_results,
)
CTkLabel(master=self.tab1, text='write here your monthly salary').pack()
self.salary_lbl_frame.pack()
self.salary_input.pack(pady=10, padx=10)
self.send_res.pack(pady=10, padx=10)
# second tab
self.results = CTkLabel(
self.tab2,
text='results',
corner_radius=15,
bg_color='black',
text_color='white',
width=999,
)
self.results.pack()
# third tab
self.exit_btn = CTkButton(
self.tab3,
text='exit',
command=self.exit,
corner_radius=45,
fg_color='maroon',
border_color='lime',
width=300
)
self.radio_var = IntVar(value=0)
self.radiobutton_month = CTkRadioButton(self.tab3, text="set month",
command=self.radiobutton_event, variable=self.radio_var, value=1).pack(pady=5)
self.radiobutton_year = CTkRadioButton(self.tab3, text="set year",
command=self.radiobutton_event, variable=self.radio_var, value=2).pack(pady=5)
self.radiobutton_week = CTkRadioButton(self.tab3, text="set week",
command=self.radiobutton_event, variable=self.radio_var, value=3).pack(pady=5)
self.radiobutton_day = CTkRadioButton(self.tab3, text="set day",
command=self.radiobutton_event, variable=self.radio_var, value=4).pack(pady=5)
self.exit_btn.place(relx=0.5, rely=0.8, anchor=CENTER)
# fourth tab
self.info = CTkLabel(master=self.tab4, text='About me\rpon')
self.info.pack()
def send_results(self):
try:
self.salary_input.update()
self.month = float(self.salary_input.get())
self.year = self.month * 12
self.day = self.month // 30
self.week = self.day * 7
self.res1 = f"monthly salary is\t{self.month}"
self.res2 = f" yearly salary is\t{self.year}"
self.res3 = f"weekly salary is\t{self.week}"
self.res4 = f"daily salary is\t{self.day}"
self.results.pack()
if self.label:
self.month_res = CTkLabel(self.tab2, text=self.res1, width=445)
self.year_res = CTkLabel(self.tab2, text=self.res2)
self.week_res = CTkLabel(self.tab2, text=self.res3)
self.day_res = CTkLabel(self.tab2, text=self.res4)
self.month_res.pack()
self.year_res.pack()
self.week_res.pack()
self.day_res.pack()
self.label = False
else:
self.month_res['text'] = self.res1
self.year_res['text'] = self.res2
self.week_res['text'] = self.res3
self.day_res['text'] = self.res4
except ValueError:
CTkInputDialog(text='Input is unreadable', title='Invalid Syntax')
@staticmethod
def exit():
exit()
def radiobutton_event(self):
print("radiobutton toggled, current value:", self.radio_var.get())
def run(self):
self.tk = CTk()
self.tk.title('Salary calculator 1.6')
self.tk.geometry('500x500+720+225')
self.tk.iconbitmap('icon.ico')
self.tk.resizable(False, False)
self.notebook_code()
self.tk.protocol("WM_DELETE_WINDOW", self.exit)
self.widgets()
self.tk.mainloop()
self.exit()
app = App()
app.run()