Here is your code reformatted to follow PEP 8 style, with added comments for clarity:
import os
import random
import string
from datetime import datetime, timedelta, date
import re
from pathlib import Path
import tkinter as tk
from tkinter import ttk, messagebox
from PIL import ImageTk
import pandas as pd
from tkcalendar import DateEntry
import customtkinter as ctk
from CTkScrollableDropdown import *
from ttkwidgets import CheckboxTreeview
# Function to generate a random 20-character ID
def generate_random_id():
return ''.join(random.choices(string.ascii_letters + string.digits, k=20))
# Declare paths for future use
# Get the Downloads path for storing the Excel file
downloads_path = str(Path.home() / "Downloads")
# Get the path for read_me.txt file
help_path = os.path.abspath("") + "\\read_me.txt"
with open(help_path, "r") as f:
read_me_text = f.read()
# Get the path for Excel file which stores employee names
name_path = f"{downloads_path}\\hr.employee.xlsx"
# Assign color palette strings
p_blue = "#0D3B66"
p_cream = "#FAF0CA"
p_yellow_l = "#F4D35E"
p_yellow_d = "#EE964B"
p_red = "#DB3A34"
p_green = "#606C38"
p_green_d = "#283618"
# Function to create the Excel file
def create_excel(data):
"""
Create or update an Excel file with new data entries.
:param data: List of data to be added to the Excel file.
"""
df_new = pd.DataFrame(data, columns=["id", "employee_id", "holiday_status_id", "date_from", "date_to"])
file_path = f"{downloads_path}\\time_off_data.xlsx"
# Merge old and new dataframes by dropping duplicates to avoid conflict
if os.path.exists(file_path):
df_ex = pd.read_excel(file_path)
df_merge = pd.concat([df_ex, df_new]).drop_duplicates(
["employee_id", "holiday_status_id", "date_from", "date_to"]
)
df_merge.to_excel(file_path, index=False)
else:
df_new.to_excel(file_path, index=False)
messagebox.showinfo("Success", "Time-Off Data Created!")
# Function to check weekend days
def check_weekend(datetime_obj):
"""
Determine if a given date is a weekday.
:param datetime_obj: A datetime object to check.
:return: False if the date is on a weekend, True otherwise.
"""
week_days = datetime_obj.strftime("%A")
return week_days not in ["Saturday", "Sunday"]
# Function to handle the submission process
def submit_data():
"""
Collect and validate user input data, then process into time-off entries.
"""
# Collect user's input
name = entry.get()
if not name:
messagebox.showerror("Error", "Please select an employee!")
return
time_off_type = time_off_option.get()
start_date = f"{cal_start.get()} {start_hour_option.get()}"
end_date = f"{cal_end.get()} {end_hour_option.get()}"
once_end_date = f"{cal_start.get()} {end_hour_option.get()}"
# Validate inputs
if not name or not time_off_type or not start_date or not end_date:
messagebox.showerror("Error", "All fields must be filled!")
return
if end_date < start_date and radio_var.get() != 3:
messagebox.showerror("Error", "End Date can't be set earlier than Start Date")
return
try:
start_dt = datetime.strptime(start_date, "%Y-%m-%d %H:%M")
end_dt = datetime.strptime(end_date, "%Y-%m-%d %H:%M")
once_end_dt = datetime.strptime(once_end_date, "%Y-%m-%d %H:%M")
except ValueError:
messagebox.showerror("Error", "Please enter valid dates in YYYY-MM-DD HH:MM format!")
return
# Process according to the recurrence type
if radio_var.get() == 2: # Weekly recurrence
end_recurring_date = cal_recurring.get()
if not end_recurring_date:
messagebox.showerror("Error", "Please provide the recurring end date!")
return
try:
recurring_end_dt = datetime.strptime(end_recurring_date, "%Y-%m-%d")
except ValueError:
messagebox.showerror("Error", "Please enter a valid recurring end date in YYYY-MM-DD format!")
return
data = []
current_start = start_dt
current_end = end_dt
while current_start.date() <= recurring_end_dt.date():
random_id = generate_random_id()
data.append([random_id, name, time_off_type, current_start, current_end])
current_start += timedelta(weeks=1)
current_end += timedelta(weeks=1)
show_confirmation_window(data, root)
elif radio_var.get() == 3: # Daily recurrence
end_recurring_date = cal_recurring.get()
if not end_recurring_date:
messagebox.showerror("Error", "Please provide the recurring end date!")
return
try:
recurring_end_dt = datetime.strptime(end_recurring_date, "%Y-%m-%d")
except ValueError:
messagebox.showerror("Error", "Please enter a valid recurring end date in YYYY-MM-DD format!")
return
data = []
current_start = start_dt
current_end = once_end_dt
while current_start.date() <= recurring_end_dt.date():
random_id = generate_random_id()
if check_weekend(current_start):
data.append([random_id, name, time_off_type, current_start, current_end])
current_start += timedelta(days=1)
current_end += timedelta(days=1)
show_confirmation_window(data, root)
elif radio_var.get() == 1: # One-time event
random_id = generate_random_id()
data = [[random_id, name, time_off_type, start_dt, end_dt]]
show_confirmation_window(data, root)
# Show confirmation window before final save
def show_confirmation_window(data, root, existing_top=None, existing_table=None, existing_check_vars=None):
"""
Display the confirmation window showing all time-off entries and allowing modifications.
:param data: List of current time-off entries.
:param root: The main tkinter root window.
:param existing_top: Existing top-level window, if available.
:param existing_table: Existing table widget to update, if available.
:param existing_check_vars: Checkbox variables for each row, if reusing widgets.
"""
def add_another_employee():
"""Add the entries to another employee."""
new_employee = entry.get()
if not new_employee:
messagebox.showerror("Error", "Please select an employee!")
return
checked_data = [row for i, row in enumerate(data) if check_vars[i].get()]
# Copy the selections and add new employee data
new_data = []
for row in checked_data:
random_id = generate_random_id()
new_data.append([random_id, new_employee, row[2], row[3], row[4]])
combined_data = checked_data + new_data
# Remove duplicates based on Name, Type, Start, and End (excluding ID)
unique_combined_data = {}
for item in combined_data:
key = (item[1], item[2], item[3], item[4])
unique_combined_data[key] = item
unique_combined_data = list(unique_combined_data.values())
# Destroy the existing confirmation window
top.destroy()
# Create a new window with updated data
show_confirmation_window(unique_combined_data, root)
# If updating existing widgets, update them instead of recreating
if existing_top and existing_table and existing_check_vars:
top = existing_top
table = existing_table
check_vars = existing_check_vars
else:
# Get master window position
root_x = root.winfo_rootx()
root_y = root.winfo_rooty()
# Add offset
win_x = root_x + 568
win_y = root_y - 31
# Toplevel window to display time-off data list
top = ctk.CTkToplevel(root)
top.wm_iconbitmap()
top.after(300, lambda: top.iconphoto(False, root.iconpath))
top.geometry("950x500" + f'+{win_x}+{win_y}')
top.title("Confirm Time-Off Entries")
# Frame to contain Treeview widget
frame = ctk.CTkFrame(top)
frame.pack(fill="both", expand=True, padx=20)
# Style for Column Headings
style = ttk.Style(top)
style.theme_use("alt")
style.configure("Treeview", foreground=p_green_d, background=p_cream, fieldbackground=p_cream,
font=("Bahnschrift", 11))
style.configure("Treeview.Heading", background=p_green, foreground=p_cream, font=("Bahnschrift", 13), hover=False)
# Table to display rows (without ID in columns but accessible in the data)
table = CheckboxTreeview(frame, columns=("Name", "Type", "Start", "End"))
# Set the headings without showing the "ID"
table.heading("Name", text="Employer Name")
table.heading("Type", text="Type of Time Off")
table.heading("Start", text="Start Date & Time")
table.heading("End", text="End Date & Time")
check_vars = []
# Label to host widgets for adding new employee
label_add_entry = ctk.CTkLabel(top)
label_add_entry.pack(padx=20, pady=15, side="top")
# Entry Box Widget Combined with Scrollable Dropdown Widget
entry = ctk.CTkEntry(master=label_add_entry, width=290, fg_color=p_cream, text_color=p_green_d,
font=("Bahnschrift", 15))
entry.grid(row=0, column=0, padx=2)
CTkScrollableDropdown(entry, values=name_list,
command=lambda e: (entry.delete(0, 'end'), entry.insert(0, e)),
fg_color=p_cream, text_color=p_cream, hover_color=p_green, autocomplete=True,
font=("Bahnschrift", 12, "bold"))
# Add Another Employee button
add_employee_button = ctk.CTkButton(master=label_add_entry, text="Apply to an Another Employee",
command=add_another_employee, width=290, fg_color=p_green,
hover_color=p_red, text_color=p_cream)
add_employee_button.configure(font=("Bahnschrift", 15, "bold"))
add_employee_button.grid(row=0, column=1, padx=2)
# Confirmation button
confirm_button = ctk.CTkButton(master=label_add_entry, text="Confirm & Save",
command=lambda: [save_confirmed_rows(data, check_vars), top.destroy()],
fg_color=p_green, hover_color=p_red, text_color=p_cream, width=290)
confirm_button.configure(font=("Bahnschrift", 15, "bold"))
confirm_button.grid(row=0, column=2, padx=2)
# Add data to the table without displaying the "ID" column
for i, row in enumerate(data):
check_var = tk.BooleanVar(value=True)
check_vars.append(check_var)
table.insert("", "end", values=(row[1], row[2], row[3], row[4]), tags=(f"row{i}",))
table.tag_bind(f"row{i}", "<<TreeviewSelect>>", lambda e, var=check_var: var.set(not var.get()))
table.check_all()
if i % 2 == 0:
table.tag_configure(f"row{i}", background=p_yellow_l)
else:
table.tag_configure(f"row{i}", background=p_yellow_d)
table.column("#0", width=50)
table.pack(expand=True, fill='both', padx=10, pady=10)
# Save only the confirmed rows
def save_confirmed_rows(data, check_vars):
"""
Save only the confirmed rows from the displayed entries.
:param data: List of current time-off entries.
:param check_vars: Checkbox variables indicating user selections.
"""
confirmed_rows = [row for i, row in enumerate(data) if check_vars[i].get()]
create_excel(confirmed_rows)
# Main GUI creation
if __name__ == "__main__":
# Initialize the GUI
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue")
root = ctk.CTk()
root.iconpath = ImageTk.PhotoImage(file=os.path.abspath("") + "\\image2nd.ico")
root.wm_iconbitmap()
root.iconphoto(False, root.iconpath)
root.title("Bulk Time-Off by M.Cetin")
root.geometry("575x350")
root.resizable(False, False)
# Employee Name Live Search
# Array for Employee Names
df_name = pd.read_excel(name_path)
name_list = df_name["name"].dropna().astype(str).to_numpy()
# Label for Widget
entry_name = tk.StringVar(value="Employee Name")
label_name = ctk.CTkLabel(root, text="Employee Search", text_color=p_cream)
label_name.configure(font=("Bahnschrift", 15, "bold"))
label_name.grid(row=0, column=0, padx=10, pady=10, sticky="w")
# Entry Box Widget Combined with Scrollable Dropdown Widget
entry = ctk.CTkEntry(root, textvariable=entry_name, width=240, fg_color=p_cream, text_color=p_green_d,
font=("Bahnschrift", 15))
entry.grid(row=0, column=1, padx=10, pady=10)
CTkScrollableDropdown(entry, values=name_list,
command=lambda e: (entry.delete(0, 'end'), entry.insert(0, e), set_available_hours(e)),
fg_color=p_cream, text_color=p_cream, hover_color=p_green, autocomplete=True,
font=("Bahnschrift", 12, "bold"))
apply_contract_var = tk.BooleanVar(value=True) # Default to checked
apply_contract_checkbox = ctk.CTkCheckBox(root, text="Apply Contract", variable=apply_contract_var,
onvalue=True, offvalue=False, text_color=p_cream)
apply_contract_checkbox.configure(font=("Bahnschrift", 15, "bold"))
apply_contract_checkbox.grid(row=6, column=2, sticky="w", padx=10, pady=10)
# Time Off Type Selection Values
time_off_type_values = df_name["time_off"].dropna().astype(str).to_numpy()
# Label for Widget
label_time_off_type = ctk.CTkLabel(root, text="Type of Time-Off:", text_color=p_cream)
label_time_off_type.configure(font=("Bahnschrift", 15, "bold"))
label_time_off_type.grid(row=1, column=0, sticky="w", padx=10, pady=10)
# Option Menu for Time off Selection
time_off_option = tk.StringVar(value="Opleiding")
time_off_menu = ctk.CTkOptionMenu(root, variable=time_off_option, width=240, values=time_off_type_values,
dropdown_fg_color=p_yellow_l, fg_color=p_yellow_l,
button_color=p_yellow_d, hover=True, button_hover_color=p_green,
dropdown_text_color=p_green_d, dropdown_hover_color=p_yellow_d,
text_color=p_green_d)
time_off_menu.configure(font=("Bahnschrift", 15, "bold"), dropdown_font=("Bahnschrift", 15, "bold"))
time_off_menu.grid(row=1, column=1, sticky="w", padx=10, pady=10)
# Create Custom Style for DateEntry Widgets
style = ttk.Style(root)
style.theme_use("alt") # Theme to be changed alt, classic, clam
style.configure("cal.DateEntry", foreground=p_cream, fieldbackground=p_green, background=p_green_d,
buttoncolor=p_green, arrowcolor=p_cream, font=("Bahnschrift", 15))
# Available Hour Options
hour_values = df_name["hours"].dropna().apply(lambda x: x.strftime('%H:%M')).to_numpy()
# Start Date Input
# Label for Widget
label_start_date = ctk.CTkLabel(root, text="Start Date", text_color=p_cream)
label_start_date.configure(font=("Bahnschrift", 15, "bold"))
label_start_date.grid(row=2, column=0, sticky="w", padx=10, pady=10)
# DateEntry for Calendar to Pick Start Date
cal_start = DateEntry(root, style="cal.DateEntry", background=p_green_d, headersbackground=p_green,
headersforeground=p_cream, normalbackground=p_cream,
othermonthwebackground=p_yellow_d, weekendbackground=p_yellow_d,
othermonthbackground=p_yellow_l, date_pattern="yyyy-mm-dd",
selectbackground=p_red)
cal_start.grid(row=2, column=1, padx=10, pady=10)
# Option Menu for Hour of Start Date
start_hour_option = tk.StringVar(value="08:00")
start_hour_menu = ctk.CTkOptionMenu(root, variable=start_hour_option, values=hour_values,
dropdown_fg_color=p_yellow_l, fg_color=p_yellow_l,
button_color=p_yellow_d, hover=True, button_hover_color=p_green,
dropdown_text_color=p_green_d, dropdown_hover_color=p_yellow_d,
text_color=p_green_d)
start_hour_menu.configure(font=("Bahnschrift", 15, "bold"), dropdown_font=("Bahnschrift", 15, "bold"))
start_hour_menu.grid(row=2, column=2, sticky="w", padx=10, pady=10)
# End Date Input
# Label for Widget
label_end_date = ctk.CTkLabel(root, text="End Date", text_color=p_cream)
label_end_date.configure(font=("Bahnschrift", 15, "bold"))
label_end_date.grid(row=3, column=0, sticky="w", padx=10, pady=10)
# DateEntry for Calendar to Pick End Date
cal_end = DateEntry(root, style="cal.DateEntry", background=p_green_d, headersbackground=p_green,
headersforeground=p_cream, normalbackground=p_cream,
othermonthwebackground=p_yellow_d, weekendbackground=p_yellow_d,
othermonthbackground=p_yellow_l, date_pattern="yyyy-mm-dd",
selectbackground=p_red)
cal_end.grid(row=3, column=1, padx=10, pady=10)
# Option Menu for Hour of End Date
end_hour_option = tk.StringVar(value="17:00")
end_hour_menu = ctk.CTkOptionMenu(root, variable=end_hour_option, values=hour_values,
dropdown_fg_color=p_yellow_l, fg_color=p_yellow_l,
button_color=p_yellow_d, hover=True, button_hover_color=p_green,
dropdown_text_color=p_green_d, dropdown_hover_color=p_yellow_d,
text_color=p_green_d)
end_hour_menu.configure(font=("Bahnschrift", 15, "bold"), dropdown_font=("Bahnschrift", 15, "bold"))
end_hour_menu.grid(row=3, column=2, sticky="w", padx=10, pady=10)
def update_cal_end_to_start(event):
"""Update cal_end to follow cal_start."""
cal_end.set_date(cal_start.get_date())
def bind_date_selection():
"""Bind the date selection event to update available hours whenever needed."""
employee_name = entry.get()
cal_start.unbind("<<DateEntrySelected>>")
cal_start.bind("<<DateEntrySelected>>", lambda event: set_available_hours(employee_name))
def radio_switch_event():
if radio_var.get() == 1:
cal_recurring.configure(state="disabled")
cal_end.configure(state="normal")
cal_start.unbind("<<DateEntrySelected>>")
elif radio_var.get() == 2:
cal_end.configure(state="normal")
cal_recurring.configure(state="normal")
cal_start.unbind("<<DateEntrySelected>>")
elif radio_var.get() == 3:
cal_end.configure(state="disabled")
cal_recurring.configure(state="normal")
cal_end.set_date(cal_start.get_date())
cal_start.bind("<<DateEntrySelected>>", update_cal_end_to_start)
bind_date_selection()
# Radiobuttons for Selecting Recurrence Option
radio_var = tk.IntVar(value=2)
radiobutton_1 = ctk.CTkRadioButton(root, text="Apply once", variable=radio_var, value=1, hover=True,
hover_color=p_red, command=radio_switch_event,
border_color=p_green, fg_color=p_red, text_color=p_cream,
text_color_disabled=p_green, border_width_checked=5,
border_width_unchecked=3, radiobutton_width=15, radiobutton_height=15)
radiobutton_2 = ctk.CTkRadioButton(root, text="Apply for each week", variable=radio_var, value=2,
hover=True, hover_color=p_red, command=radio_switch_event,
border_color=p_green, fg_color=p_red, text_color=p_cream,
text_color_disabled=p_green, border_width_checked=5,
border_width_unchecked=3, radiobutton_width=15, radiobutton_height=15)
radiobutton_3 = ctk.CTkRadioButton(root, text="Apply for each day", variable=radio_var, value=3,
hover=True, hover_color=p_red, command=radio_switch_event,
border_color=p_green, fg_color=p_red, text_color=p_cream,
text_color_disabled=p_green, border_width_checked=5,
border_width_unchecked=3, radiobutton_width=15, radiobutton_height=15)
radiobutton_1.configure(font=("Bahnschrift", 15, "bold"))
radiobutton_2.configure(font=("Bahnschrift", 15, "bold"))
radiobutton_3.configure(font=("Bahnschrift", 15, "bold"))
radiobutton_1.grid(row=4, column=0, padx=10, pady=10)
radiobutton_2.grid(row=4, column=1, padx=10, pady=10)
radiobutton_3.grid(row=4, column=2, padx=10, pady=10)
# End Date for Recurring Option
# Label for Widget
label_end_recurring_date = ctk.CTkLabel(root, text="End Recurring Date", text_color=p_cream)
label_end_recurring_date.configure(font=("Bahnschrift", 15, "bold"))
label_end_recurring_date.grid(row=5, column=0, sticky="w", padx=10, pady=10)
# DateEntry for Calendar to Pick Recurring Date
cal_recurring = DateEntry(root, style="cal.DateEntry", background=p_green_d, headersbackground=p_green,
headersforeground=p_cream, normalbackground=p_cream,
othermonthwebackground=p_yellow_d, weekendbackground=p_yellow_d,
othermonthbackground=p_yellow_l, date_pattern="yyyy-mm-dd",
selectbackground=p_red)
cal_recurring.grid(row=5, column=1, padx=10, pady=10)
# Function to Parse Working Hours from Contract Name
def parse_contract_hours(contract_name):
"""
Extract start and end working hours for each weekday from a contract string.
:param contract_name: The name of the contract which contains hour info.
:return: A list of tuples of start and end times per weekday (None if parsing fails).
"""
numbers = re.findall(r'\d+[\.,]?\d*', contract_name) # Capture decimal numbers too
if len(numbers) < 5:
return [None] * 5 # Return list of None if not enough data
days_hours = [float(n.replace(',', '.')) for n in numbers[:5]]
start_time_match = re.search(r'start (\d{2}:\d{2})', contract_name)
start_times = []
if start_time_match:
start_time_str = start_time_match.group(1)
start_hour, start_minute = map(int, start_time_str.split(':'))
start_dt = datetime(2023, 1, 1, start_hour, start_minute)
for day_hours in days_hours:
end_dt = calculate_end_time_with_breaks(start_dt, day_hours)
start_times.append((start_dt.time(), end_dt.time()))
else:
return [None] * 5 # Return list of None if no start time
return start_times
def calculate_end_time_with_breaks(start_dt, working_hours):
"""
Calculate end time of a workday considering built-in breaks.
:param start_dt: Start datetime object.
:param working_hours: Hours worked in decimal.
:return: The calculated end datetime after breaks.
"""
hours = int(working_hours)
minutes = int((working_hours - hours) * 60)
current_end_dt = start_dt + timedelta(hours=hours, minutes=minutes)
# Define break times and durations
breaks = [
(datetime(2023, 1, 1, 10, 0), timedelta(minutes=15)), # 10:00 AM break
(datetime(2023, 1, 1, 12, 30), timedelta(minutes=30)), # 12:30 PM break
(datetime(2023, 1, 1, 14, 30), timedelta(minutes=15)) # 2:30 PM break
]
# Check if a break happens within the schedule and adjust end time
for break_start, break_duration in breaks:
break_start, break_end = (break_start.time(), (break_start + break_duration).time())
if start_dt.time() <= break_start and break_start < current_end_dt.time():
current_end_dt += break_duration
return current_end_dt
# Function to Filter Available Hours based on Contract
def set_available_hours(employee_name):
"""
Set available work hours according to the selected employee's contract.
:param employee_name: Name of the selected employee.
"""
if apply_contract_var.get():
employee_data = df_name[df_name['name'] == employee_name]
if not employee_data.empty:
contract_name = employee_data['contract_name'].values[0]
weekday_start_end_times = parse_contract_hours(contract_name)
if weekday_start_end_times:
cal_start.bind("<<DateEntrySelected>>",
lambda event: update_available_hours(cal_start, weekday_start_end_times))
update_available_hours(cal_start, weekday_start_end_times)
else:
reset_to_standard_hours()
else:
reset_to_standard_hours()
else:
reset_to_standard_hours()
def update_available_hours(date_entry, weekday_start_end_times):
"""
Update start and end time availability based on selected weekday.
:param date_entry: The DateEntry widget currently being used.
:param weekday_start_end_times: List of start and end times for weekdays.
"""
selected_date = date_entry.get_date()
weekday_index = selected_date.weekday()
if weekday_index in [5, 6]: # 5 = Saturday, 6 = Sunday
messagebox.showerror("Error", "Selected date falls on a weekend. Please choose a weekday.")
date_entry.set_date(date.today())
return
start_end_times = weekday_start_end_times[weekday_index]
if start_end_times is None:
reset_to_standard_hours()
return
start_time, end_time = start_end_times
available_hours = []
current_time = datetime.combine(datetime.today(), start_time)
last_time = datetime.combine(datetime.today(), end_time)
while current_time <= last_time:
available_hours.append(current_time.strftime("%H:%M"))
current_time += timedelta(minutes=30)
start_hour_menu.configure(values=available_hours)
end_hour_menu.configure(values=available_hours)
if available_hours:
start_hour_option.set(available_hours[0])
end_hour_option.set(available_hours[-1])
if not apply_contract_var.get():
reset_to_standard_hours()
def reset_to_standard_hours():
"""Reset to standard available hours if contract hours can't be applied."""
start_hour_menu.configure(values=hour_values)
end_hour_menu.configure(values=hour_values)
start_hour_option.set(hour_values[0])
end_hour_option.set(hour_values[-1])
# Toplevel window to display read_me.txt File
def read_me_top():
"""
Open a top-level window to display additional help/information from the read_me.txt file.
"""
root_x = root.winfo_rootx()
root_y = root.winfo_rooty()
win_x = root_x - 9
win_y = root_y + 351
top = ctk.CTkToplevel()
top.wm_iconbitmap()
top.after(200, lambda: top.iconphoto(False, root.iconpath))
top.title("READ ME")
top.geometry("575x200" + f'+{win_x}+{win_y}')
top.resizable(False, False)
top.attributes('-topmost', True)
s_frame = ctk.CTkScrollableFrame(top, scrollbar_button_color=p_green)
s_frame.pack(fill="both", expand=True, padx=5, pady=5)
label_read = ctk.CTkLabel(s_frame, text=str(read_me_text), corner_radius=3, fg_color=p_cream,
text_color=p_green_d, wraplength=500)
label_read.configure(font=("Bahnschrift", 15), justify="left")
label_read.pack(expand=True, fill="both", padx=5, pady=5)
# Button for Toplevel READ ME Event
button_help = ctk.CTkButton(root, text="?", corner_radius=10, fg_color=p_red, text_color=p_cream, width=30,
command=read_me_top)
button_help.configure(font=("Bahnschrift", 15, "bold"))
button_help.grid(row=6, column=0, padx=10, pady=10, sticky="w")
# Submit Button
submit_button = ctk.CTkButton(root, text="Create Time-Off Data", command=submit_data, corner_radius=10,
fg_color=p_blue, text_color=p_cream, hover_color=p_red)
submit_button.configure(font=("Bahnschrift", 15, "bold"))
submit_button.grid(row=6, column=1, padx=10, pady=10)
bind_date_selection()
root.mainloop()
Key Changes and Additions:
- Organized imports and added spaces between sections for better readability.
- Reformatted comments and docstrings to describe function purposes and parameters.
- Split long lines for improved clarity according to PEP 8 recommendations (79 characters per line when possible).
- Improved consistency in naming conventions and styling across the code.