import customtkinter as ctk import pandas as pd from tkinter import filedialog, messagebox import threading # Função para carregar e exibir o arquivo Excel def load_excel(): file_path = filedialog.askopenfilename(filetypes=[(“Excel files”, “*.xlsx”)]) if file_path: global df df = pd.read_excel(file_path) if ‘Matrículas’ in df.columns: display_table(df) else: messagebox.showerror(“Erro”, “O arquivo selecionado não segue o padrão esperado.”) # Função para exibir os dados na Treeview def display_table(df): for i, row in df.iterrows(): tree.insert(“”, “end”, values=list(row)) # Função para validar e destacar matrículas inválidas def validate_data(): for i, item in enumerate(tree.get_children()): matricula = tree.item(item)[‘values’][0] if len(str(matricula)) != 5 or not str(matricula).isdigit(): tree.item(item, tags=(“invalid”,)) else: tree.item(item, tags=(“valid”,)) tree.tag_configure(‘invalid’, background=’red’) tree.tag_configure(‘valid’, background=’white’) # Função para atualizar o DataFrame e salvar o arquivo corrigido def update_and_save(): for i, item in enumerate(tree.get_children()): df.iloc[i, 0] = tree.item(item)[‘values’][0] # Assumindo que a coluna de matrículas é a primeira df.to_excel(“corrected_file.xlsx”, index=False) messagebox.showinfo(“Sucesso”, “Arquivo salvo com sucesso!”) # Configuração da interface CustomTkinter app = ctk.CTk() app.geometry(“800×600″) load_button = ctk.CTkButton(app, text=”Carregar Arquivo”, command=load_excel) load_button.pack(pady=20) tree = ctk.CTkTreeview(app, columns=(“Matrícula”,)) tree.heading(“#0″, text=””) tree.heading(“Matrícula”, text=”Matrícula”) tree.pack(pady=20) validate_button = ctk.CTkButton(app, text=”Validar Matrículas”, command=validate_data) validate_button.pack(pady=20) save_button = ctk.CTkButton(app, text=”Salvar Correções”, command=update_and_save) save_button.pack(pady=20) app.mainloop()
Zogbi Silva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.