Payment

tk.Frame.__init__(self, *args, **kwargs)
self.root = tk.Toplevel()
self.root.title("Salary Slip")
color = "#FFFFFF"
self.root.configure(bg="#585858")
self.root.resizable(width=0, height=0)
win_width = 1280
win_height = int(1280 * 56.25 / 100)
self.root.geometry(str(win_width) + "x" + str(win_height))
Util.center(self.root)
# Get screen size
screen_width = self.root.winfo_screenwidth()
screen_height = self.root.winfo_screenheight()
Util.set_font_size(screen_width, screen_height, win_width, win_height)
self.width = win_width * 96 / 100
self.height = win_height * 94 / 100
After creation of window, we will add a canvas background.
bg_canvas = RoundBackgroundFrame(self.root, self.width, self.height, padding, corner_radius, self.color,
"#585858")
bg_canvas.place(width=self.width, height=self.height, x=win_width / 2 - self.width / 2,
y=win_height / 2 - self.height / 2)
self.width = self.width * 98 / 100
self.height = self.height * 96 / 100
self.base_frame = Frame(self.root, width=self.width, height=self.height, bg=self.color)
bg_canvas.create_window(self.width / 100, self.height * 2 / 100, anchor=NW, window=self.base_frame)
# Add Heading Label
add_heading_label(self.base_frame, self.color, AppConstant.FONT_SIZE, self.height, self.width)
def add_heading_label(base_frame, color, font_size, height, width):
label_heading = Label(base_frame, text="Payment", anchor=CENTER, bg=color,
font=("Lucida Grande", font_size + 12))
label_heading.place(width=width * 90 / 100, height=60, x=width * 5 / 100, y=height * 2 / 100)
# Add Line Border
add_line_border(self.base_frame, self.color, self.height, self.width)
def add_line_border(base_frame, color, width, pos_x, pos_y):
line_canvas = Canvas(base_frame, bg=color, borderwidth=0, relief="flat", highlightthickness=0)
line_canvas.place(width=width - 4, height=4, x=pos_x, y=pos_y)
line_canvas.create_line(0, 0, width, 0, fill="#787878")
# Add Action frame
add_action_frame(self.base_frame, self.color, self.height, self.width)
def add_action_frame(base_frame, color, height, width):
afw = width * 1.0
afh = height * 0.80
button_font = ("Lucida Grande", AppConstant.FONT_SIZE - 6)
label_frame_action = LabelFrame(base_frame, text="Salary Slip", font=button_font, pady=afw * 2 / 100,
padx=afw * 2 / 100, bg=color)
label_frame_action.place(width=afw, height=afh, x=0, y=height * 0.15)
return button_font
# Shop Name Label
label_shop_name = Label(self.base_frame, text="Neeraj Store", anchor=CENTER, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE))
label_shop_name.place(width=self.width * 90 / 100, height=self.height * 7 / 100,
x=self.width * 5 / 100, y=self.height * 18 / 100)
# shop address label
shop_address = "#41113, DLF City 2nd Cross, Schemencherry, Bangalore(KA)"
label_shop_address = Label(self.base_frame, text=shop_address, anchor=CENTER, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
label_shop_address.place(width=self.width * 90 / 100, height=self.height * 7 / 100,
x=self.width * 5 / 100, y=self.height * 23 / 100)
# Shop gst label
shop_gst = "GSTIN1253****"
label_shop_gst = Label(self.base_frame, text="GSTIN- " + shop_gst, anchor=CENTER, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
label_shop_gst.place(width=self.width * 90 / 100, height=self.height * 5 / 100,
x=self.width * 5 / 100, y=self.height * 28 / 100)
# staff id label
self.label_staff_id = Label(self.base_frame, text="Staff Id : ", anchor=W, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
self.label_staff_id.place(width=self.width * 20 / 100, height=self.height * 5 / 100,
x=self.width * 5 / 100, y=self.height * 33 / 100)
# Staff contact no label
self.label_staff_phone_no = Label(self.base_frame, text="Contact No : ", anchor=W, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
self.label_staff_phone_no.place(width=self.width * 20 / 100, height=self.height * 5 / 100,
x=self.width * 75 / 100, y=self.height * 33 / 100)
# Staff name label
self.label_staff_name = Label(self.base_frame, text="Staff Name: ", anchor=W, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
self.label_staff_name.place(width=self.width * 20 / 100, height=self.height * 5 / 100,
x=self.width * 5 / 100, y=self.height * 37 / 100)
# Staff payment_mode label
self.label_staff_payment_mode = Label(self.base_frame, text="Payment Mode: ", anchor=W, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
self.label_staff_payment_mode.place(width=self.width * 20 / 100, height=self.height * 5 / 100,
x=self.width * 75 / 100, y=self.height * 37 / 100)
# Add Line Border
add_line_border(self.base_frame, self.color, self.width * 94 / 100, self.width * 3 / 100,
self.height * 45 / 100)
# Add Advance label
label_advance_text = Label(self.base_frame, text="Advance: ", anchor=W, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
label_advance_text.place(width=self.width * 15 / 100, height=self.height * 5 / 100,
x=self.width * 70 / 100, y=self.height * 78 / 100)
#Add Pending label
label_pending_text = Label(self.base_frame, text="Pending: ", anchor=W, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
label_pending_text.place(width=self.width * 15 / 100, height=self.height * 5 / 100,
x=self.width * 70 / 100, y=self.height * 82 / 100)
#Add Total label
label_total_text = Label(self.base_frame, text="Total: ", anchor=W, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
label_total_text.place(width=self.width * 15 / 100, height=self.height * 5 / 100,
x=self.width * 70 / 100, y=self.height * 89 / 100)
self.calculate_salary()
self.show_salary_table()
#Add Line Border
add_line_border(self.base_frame, self.color, self.width * 94 / 100, self.width * 3 / 100,
self.height * 88 / 100)
def show_salary_table(self):
self.tree = ttk.Treeview(self.base_frame, columns=("c1", "c2", "c3", "c4", "c5"),
selectmode="extended", show='tree')
self.tree.place(width=self.width * 94 / 100, height=self.height * 10 / 100,
x=self.width * 3 / 100, y=self.height * 55 / 100)
self.tree.heading("#1", text="S.No.", anchor=tk.CENTER)
self.tree.heading("#2", text="Date", anchor=tk.W)
self.tree.heading("#3", text="Working Hours", anchor=tk.CENTER)
self.tree.heading("#4", text="Salary", anchor=tk.E)
self.tree.column("#0", width=0, anchor=tk.CENTER)
self.tree.column("#1", width=int(self.width * 8 / 100), anchor=tk.CENTER)
self.tree.column("#2", width=int(self.width * 42 / 100), anchor=tk.W)
self.tree.column("#3", width=int(self.width * 10 / 100), anchor=tk.CENTER)
self.tree.column("#4", width=int(self.width * 20 / 100), anchor=tk.E)
self.tree.column("#5", width=int(self.width * 10 / 100), anchor=tk.E)
self.get_table_data(AppConstant.STAFF_ID)
self.product_table_heading()
We have created our own heading for table, lets configure it.
def product_table_heading(self):
heading_y = self.height * 46 / 100
bg_color = "#FF4F00"
text_color = "#000000"
canvas = Canvas(self.base_frame, width=self.width * 93 / 100, height=self.height * 5 / 100)
canvas.create_rectangle(0, 0, self.width * 94 / 100, self.height * 5 / 100, fill=bg_color)
canvas.place(height=self.height * 5 / 100,
x=self.width * 3 / 100, y=heading_y - 2)
label_sno = ttk.Label(self.base_frame, text="S.No.", anchor="center",
font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'),
background=bg_color, foreground=text_color)
label_sno.place(width=self.width * 12 / 100, height=self.height * 5 / 100,
x=self.width * 3 / 100, y=heading_y)
label_date = ttk.Label(self.base_frame, text="Date", anchor="w",
font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
foreground=text_color)
label_date.place(width=self.width * 35 / 100, height=self.height * 5 / 100,
x=self.width * 15 / 100, y=heading_y)
label_working_hour = ttk.Label(self.base_frame, text="Working Hour", anchor="center",
font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
foreground=text_color)
label_working_hour.place(width=self.width * 25 / 100, height=self.height * 5 / 100,
x=self.width * 50 / 100, y=heading_y)
label_salary = ttk.Label(self.base_frame, text="Salary", anchor="center",
font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
foreground=text_color)
label_salary.place(width=self.width * 22 / 100, height=self.height * 5 / 100,
x=self.width * 75 / 100, y=heading_y)
Here we retrieve data from database
def get_table_data(self, staff_id):
db = Util.connect_db()
cursor = db.cursor()
cursor.execute('SELECT * FROM staff_data WHERE staff_id =?', (staff_id,))
sql_output = cursor.fetchall()
date = dt.datetime.now()
format_date = f"{date:%a, %b %d %Y}"
total_amount = sql_output[0][5] * 100
total_advance = 0
total_pending = 0
total_salary = total_amount + total_pending - total_advance
self.label_total.config(text=str(total_amount))
self.tree.insert("", 'end', values=("1.", format_date, sql_output[0][5], total_amount))
self.label_staff_id.config(text="Staff Id: " + str(sql_output[0][0]))
self.label_staff_name.config(text="Staff Name: " + str(sql_output[0][1]))
self.label_staff_phone_no.config(text="Contact No.: " + str(sql_output[0][2]))
self.label_staff_payment_mode.config(text="Payment Mode: " + str(sql_output[0][4]))
Here we calculate the salry of the employee
def calculate_salary(self):
self.label_advance = Label(self.base_frame, text="- " + "00", anchor=E, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
self.label_advance.place(width=self.width * 10 / 100, height=self.height * 5 / 100,
x=self.width * 77 / 100, y=self.height * 78 / 100)
self.label_pending = Label(self.base_frame, text="+ " + "00", anchor=E, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
self.label_pending.place(width=self.width * 10 / 100, height=self.height * 5 / 100,
x=self.width * 77 / 100, y=self.height * 82 / 100)
self.label_total = Label(self.base_frame, text="=10000", anchor=E, bg=self.color,
font=("Lucida Grande", AppConstant.FONT_SIZE - 5))
self.label_total.place(width=self.width * 10 / 100, height=self.height * 5 / 100,
x=self.width * 77 / 100, y=self.height * 89 / 100)
At last we will manage closing of window
def on_closing():
self.root.destroy()
args[0].deiconify()
self.root.protocol("WM_DELETE_WINDOW", on_closing)
Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.
Copyright 2021 by Programmer Mitra. All Rights Reserved.