Apologies for the confusion. If you don't want to use the tkbootstrap library and you don't have any specific third-party libraries available, you can still make your UI appear modern by customizing it using native Tkinter options. Here's an updated version of your script with a modern and minimalistic style:
import csv
import os
import tkinter as tk
from tkinter import filedialog, messagebox
def process_csv(file_path, output_directory):
# Extract the original file name without extension
file_name = os.path.splitext(os.path.basename(file_path))[0]
# Read the CSV file
with open(file_path, "r") as csv_file:
reader = csv.reader(csv_file)
rows = list(reader)
# Check if the first line contains letters
if any(c.isalpha() for c in rows[0][0]):
# Remove the first line
rows.pop(0)
# Remove the first two characters from the first column if they are letters
for i in range(len(rows)):
if rows[i][0][:2].isalpha():
rows[i][0] = rows[i][0][2:]
# Construct the output file name
output_file_name = file_name + "_Modified.csv"
# Construct the full output file path
output_file_path = os.path.join(output_directory, output_file_name)
# Write the processed CSV to a new file
with open(output_file_path, "w", newline="") as csv_file:
writer = csv.writer(csv_file)
writer.writerows(rows)
messagebox.showinfo("Success", "Modified CSV file has been saved successfully.")
def browse_file():
file_path = filedialog.askopenfilename()
entry_file_path.delete(0, tk.END)
entry_file_path.insert(0, file_path)
def browse_directory():
output_directory = filedialog.askdirectory()
entry_output_directory.delete(0, tk.END)
entry_output_directory.insert(0, output_directory)
def process():
file_path = entry_file_path.get()
output_directory = entry_output_directory.get()
if file_path == "" or output_directory == "":
messagebox.showerror("Error", "Please specify the input file and output directory.")
return
process_csv(file_path, output_directory)
# Create the main window
window = tk.Tk()
window.title("CSV Processing")
# Set a modern and minimalistic style
window.option_add("*Font", "Helvetica")
window.option_add("*Button.background", "lightgray")
window.option_add("*Button.font", "Helvetica")
window.option_add("*Label.font", "Helvetica")
window.option_add("*Entry.font", "Helvetica")
# Create and place the widgets with modern styling
label_file_path = tk.Label(window, text="CSV File Path:")
label_file_path.pack()
entry_file_path = tk.Entry(window, width=50)
entry_file_path.pack()
button_browse_file = tk.Button(window, text="Browse", command=browse_file)
button_browse_file.pack()
label_output_directory = tk.Label(window, text="Modified CSV Output:")
label_output_directory.pack()
entry_output_directory = tk.Entry(window, width=50)
entry_output_directory.pack()
button_browse_directory = tk.Button(window, text="Browse", command=browse_directory)
button_browse_directory.pack()
button_process = tk.Button(window, text="Process", command=process)
button_process.pack()
# Run the main event loop
window.mainloop()
In this updated script, we've used native Tkinter options to apply a modern and minimalistic style. The window.option_add() lines set various options such as font, button background color, and label font. Modify these options as per your preference to achieve the desired style.
Please note that this method offers a basic styling approach, and for more advanced and customizable styles, third-party libraries like tkbootstrap, ttkthemes, or others are recommended.