import tkinter as tk
import sqlite3
def compare_sql():
# 从文本框获取输入的SQL语句
sql = sql_entry.get("1.0", tk.END).strip()
# 连接数据库
conn = sqlite3.connect("your_database.db")
cursor = conn.cursor()
try:
# 执行SQL查询
cursor.execute(sql)
result = cursor.fetchall()
# 清空结果展示框
result_text.delete("1.0", tk.END)
# 展示查询结果
for row in result:
result_text.insert(tk.END, str(row) + "\n")
except Exception as e:
# 处理异常情况
result_text.delete("1.0", tk.END)
result_text.insert(tk.END, "Error: " + str(e))
# 关闭数据库连接
cursor.close()
conn.close()
# 创建主窗口
window = tk.Tk()
window.title("SQL Compare Tool")
# 创建文本框用于输入SQL语句
sql_entry = tk.Text(window, height=10)
sql_entry.pack()
# 创建确认按钮
compare_button = tk.Button(window, text="Compare", command=compare_sql)
compare_button.pack()
# 创建结果展示框
result_text = tk.Text(window, height=20)
result_text.pack()
# 运行主循环
window.mainloop()
标签:END,text,sql,查询,window,result,SQL,工具,tk
From: https://blog.51cto.com/u_15145577/7869946