gpt-4-0314· openai
Suzhen/CodeChat
写一段Python代码,用tkinter实现: 1,后台数据库是指定的Excel文件 1,在搜索框输入手机号,点击查询,查找信息并返回输出到文本框显示
- User
写一段Python代码,用tkinter实现: 1,后台数据库是指定的Excel文件 1,在搜索框输入手机号,点击查询,查找信息并返回输出到文本框显示
- Assistant
import tkinter as tk from tkinter import messagebox import openpyxl def search(): phone_number = entry_phone.get() if phone_number == "": messagebox.showwarning("提示", "请输入手机号") else: excel_file = 'sample_excel_file.xlsx' wb = openpyxl.load_workbook(excel_file) ws = wb.active found = False for row in ws.iter_rows(min_row=2, values_only=True): if row[0] == phone_number: text_result.delete(1.0, tk.END) result = f"手机号: {row[0]}, 姓名: {row[1]}, 住址: {row[2]}" text_result.insert(tk.END, result) found = True break if not found: messagebox.showinfo("提示", "手机号未找到") wb.close() app = tk.Tk() app.title("查询手机号") app.geometry("400x200") label_phone = tk.Label(app, text="手机号") label_phone.place(x=10, y=10, width=80, height=40) entry_phone = tk.Entry(app) entry_phone.place(x=100, y=10, width=200, height=40) search_button = tk.Button(app, text="查询", command=search) search_button.place(x=300, y=10, width=80, height=40) text_result = tk.Text(app) text_result.place(x=10, y=60, width=380, height=130) app.mainloop()