vlookup using .py file,taking input files and column from user

import pandas as pd
import tkinter as tk
from tkinter import filedialog, messagebox

def select_file():
    file_path = filedialog.askopenfilename(filetypes=[("Excel files", "*.xls *.xlsx")])
    if file_path:
        return file_path
    else:
        messagebox.showwarning("No file selected", "Please select a file.")
        return None

def load_columns(file_path, listbox):
    df = pd.read_excel(file_path, None)
    columns = df[list(df.keys())[0]].columns.tolist()
    listbox.delete(0, tk.END)
    for col in columns:
        listbox.insert(tk.END, col)
    return df

def on_select_main(event):
    global main_selected_column
    main_selected_column = main_listbox.get(main_listbox.curselection())
    messagebox.showinfo("Selected Column", f"You selected (Main File): {main_selected_column}")

def on_select_lookup(event):
    global lookup_selected_column
    lookup_selected_column = lookup_listbox.get(lookup_listbox.curselection())
    messagebox.showinfo("Selected Column", f"You selected (Lookup File): {lookup_selected_column}")

def on_select_lookup_columns(event):
    global lookup_selected_columns
    selected_indices = lookup_listbox.curselection()
    lookup_selected_columns = [lookup_listbox.get(i) for i in selected_indices]
    messagebox.showinfo("Selected Columns", f"You selected (Lookup File Columns): {', '.join(lookup_selected_columns)}")

def vlookup_data(main_file_path, lookup_file_path, main_col, lookup_col, lookup_cols):
    main_xls = pd.ExcelFile(main_file_path)
    lookup_xls = pd.ExcelFile(lookup_file_path)
    
    main_sheets = main_xls.sheet_names
    lookup_sheets = lookup_xls.sheet_names
    
    writer = pd.ExcelWriter(main_file_path, engine='openpyxl')
    
    for sheet in main_sheets:
        main_df = pd.read_excel(main_xls, sheet_name=sheet)
        
        for lookup_sheet in lookup_sheets:
            lookup_df = pd.read_excel(lookup_xls, sheet_name=lookup_sheet)
            
            merged_df = pd.merge(main_df, lookup_df[[lookup_col] + lookup_cols], how='left', left_on=main_col, right_on=lookup_col)
            merged_df.drop(columns=[lookup_col], inplace=True)
            
            main_df = merged_df
        
        main_df.to_excel(writer, sheet_name=sheet, index=False)
    
    writer.save()
    messagebox.showinfo("Success", "VLOOKUP operation completed successfully.")
    print(f"File saved successfully: {main_file_path}")

def start_vlookup():
    global main_file_path, lookup_file_path, main_selected_column, lookup_selected_column, lookup_selected_columns
    if main_selected_column and lookup_selected_column and lookup_selected_columns:
        vlookup_data(main_file_path, lookup_file_path, main_selected_column, lookup_selected_column, lookup_selected_columns)
    else:
        messagebox.showwarning("Selection Missing", "Please select all necessary columns.")

app = tk.Tk()
app.title("VLOOKUP Across Multiple Sheets")
app.geometry("800x600")

main_file_path = None
lookup_file_path = None
main_selected_column = None
lookup_selected_column = None
lookup_selected_columns = []

frame = tk.Frame(app)
frame.pack(pady=20)

main_file_button = tk.Button(frame, text="Load Main Excel File", command=lambda: load_columns(select_file(), main_listbox))
main_file_button.pack(pady=5)

main_listbox = tk.Listbox(frame, selectmode=tk.SINGLE, width=50, height=10)
main_listbox.pack(pady=5)
main_listbox.bind("<<ListboxSelect>>", on_select_main)

lookup_file_button = tk.Button(frame, text="Load Lookup Excel File", command=lambda: load_columns(select_file(), lookup_listbox))
lookup_file_button.pack(pady=5)

lookup_listbox = tk.Listbox(frame, selectmode=tk.MULTIPLE, width=50, height=10)
lookup_listbox.pack(pady=5)
lookup_listbox.bind("<<ListboxSelect>>", on_select_lookup)

lookup_columns_button = tk.Button(frame, text="Select Lookup Columns", command=lambda: on_select_lookup_columns(None))
lookup_columns_button.pack(pady=5)

start_button = tk.Button(frame, text="Start VLOOKUP", command=start_vlookup)
start_button.pack(pady=20)

app.mainloop()


    

I tried this code to open main file and lookup file ,i want to select common column but condition is i might have different column name in both file,SO how to do left on and right on. The script should allow me to select a main file and a lookup file, select the common columns and the columns to be looked up, and perform the VLOOKUP operation across multiple sheets.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật