import tkinter as tk
from tkinter import messagebox
import sqlite3
import pandas as pd
# 连接到SQLite数据库
def connect_to_db():
conn = sqlite3.connect('students.db')
cursor = conn.cursor()
return conn, cursor
# 从Excel文件读取数据并导入到SQLite数据库
def import_data_from_excel():
try:
df = pd.read_excel('students.xlsx', sheet_name='Sheet1')
conn, cursor = connect_to_db()
df.to_sql('students', conn, if_exists='append', index=False)
conn.commit()
messagebox.showinfo("Success", "Data imported successfully!")
except FileNotFoundError:
messagebox.showerror("Error", "The file students.xlsx does not exist.")
except Exception as e:
messagebox.showerror("