|
|
|
@ -1,14 +1,18 @@
|
|
|
|
|
import tkinter as tk
|
|
|
|
|
from tkinter import messagebox, ttk
|
|
|
|
|
import pymysql
|
|
|
|
|
import datetime
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MasterChargeSystem(tk.Tk):
|
|
|
|
|
current_username=None
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.login_frame = None
|
|
|
|
|
self.register_frame = None
|
|
|
|
|
self.comment_frame = None
|
|
|
|
|
self.detail_window = None
|
|
|
|
|
self.create_login_window()
|
|
|
|
|
|
|
|
|
|
def register_database(self, username, password):
|
|
|
|
@ -19,11 +23,13 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
connection.commit()
|
|
|
|
|
|
|
|
|
|
def login(self):
|
|
|
|
|
global current_username
|
|
|
|
|
username = self.username_entry.get().strip()
|
|
|
|
|
password = self.password_entry.get().strip()
|
|
|
|
|
|
|
|
|
|
with pymysql.connect(host='localhost', user='root', password='123456', database='mynewdb') as connection:
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
current_username=username
|
|
|
|
|
sql = "SELECT password FROM user1 WHERE username = %s"
|
|
|
|
|
cursor.execute(sql, (username,))
|
|
|
|
|
result = cursor.fetchone()
|
|
|
|
@ -58,9 +64,11 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
self.login_frame.pack_forget()
|
|
|
|
|
if self.comment_frame:
|
|
|
|
|
self.comment_frame.pack_forget()
|
|
|
|
|
if self.detail_window:
|
|
|
|
|
self.detail_window.pack_forget()
|
|
|
|
|
|
|
|
|
|
self.title("考研信息系统")
|
|
|
|
|
self.attributes('-fullscreen', True)
|
|
|
|
|
self.attributes('-fullscreen',True)
|
|
|
|
|
|
|
|
|
|
self.main_frame = tk.Frame(self)
|
|
|
|
|
self.main_frame.pack(fill=tk.BOTH, expand=True, padx=50, pady=50)
|
|
|
|
@ -68,40 +76,69 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
main_label = tk.Label(self.main_frame, text="欢迎来到考研信息系统!")
|
|
|
|
|
main_label.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
# 添加搜索框
|
|
|
|
|
search_frame = tk.Frame(self.main_frame)
|
|
|
|
|
search_frame.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
search_label = tk.Label(search_frame, text="搜索:")
|
|
|
|
|
search_label.pack(side=tk.LEFT)
|
|
|
|
|
|
|
|
|
|
self.search1_entry = tk.Entry(search_frame)
|
|
|
|
|
self.search1_entry.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
|
|
|
|
self.search2_entry = ttk.Combobox(search_frame, values=['1', '2'])
|
|
|
|
|
self.search2_entry.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
affirm_button = tk.Button(search_frame, text="确认", command=self.search_data)
|
|
|
|
|
affirm_button.pack(side=tk.RIGHT)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
with pymysql.connect(host='localhost', user='root', password='123456', database='mynewdb') as connection:
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
cursor.execute("SELECT * FROM universities_beijing")
|
|
|
|
|
|
|
|
|
|
# 添加搜索框
|
|
|
|
|
search_frame = tk.Frame(self.main_frame)
|
|
|
|
|
search_frame.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
search_label = tk.Label(search_frame, text="搜索:地区")
|
|
|
|
|
search_label.pack(side=tk.LEFT)
|
|
|
|
|
|
|
|
|
|
cursor.execute("select distinct 省份 from universities_beijing")
|
|
|
|
|
location = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
self.search2_entry = ttk.Combobox(search_frame, values=location)
|
|
|
|
|
self.search2_entry.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
|
|
|
|
cursor.execute("select distinct 招生年份 from universities_beijing")
|
|
|
|
|
year = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
search_label = tk.Label(search_frame, text=" 年份")
|
|
|
|
|
search_label.pack(side=tk.LEFT)
|
|
|
|
|
|
|
|
|
|
self.search3_entry = ttk.Combobox(search_frame, values=year)
|
|
|
|
|
self.search3_entry.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
|
|
|
|
cursor.execute("select distinct 学校类型 from universities_beijing")
|
|
|
|
|
time = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
search_label = tk.Label(search_frame, text=" 学校类型")
|
|
|
|
|
search_label.pack(side=tk.LEFT)
|
|
|
|
|
|
|
|
|
|
self.search4_entry = ttk.Combobox(search_frame, values=time)
|
|
|
|
|
self.search4_entry.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
|
|
|
|
search_label = tk.Label(search_frame, text=" 院校")
|
|
|
|
|
search_label.pack(side=tk.LEFT)
|
|
|
|
|
|
|
|
|
|
self.search1_entry = tk.Entry(search_frame)
|
|
|
|
|
self.search1_entry.pack(side=tk.LEFT, padx=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
affirm_button = tk.Button(search_frame, text="确认", command=self.search_data)
|
|
|
|
|
affirm_button.pack(side=tk.RIGHT)
|
|
|
|
|
# self.search_entry.bind("<KeyRelease>", self.search_data) #自动读取键盘输入搜索
|
|
|
|
|
|
|
|
|
|
# 创建一个用于 Treeview 和滚动条的框架
|
|
|
|
|
tree_frame = tk.Frame(self.main_frame)
|
|
|
|
|
tree_frame.pack(fill=tk.BOTH, expand=True)
|
|
|
|
|
|
|
|
|
|
self.tree = ttk.Treeview(tree_frame)
|
|
|
|
|
|
|
|
|
|
self.vertical_scrollbar = ttk.Scrollbar(tree_frame, orient=tk.VERTICAL, command=self.tree.yview)
|
|
|
|
|
|
|
|
|
|
self.tree.configure(yscrollcommand=self.vertical_scrollbar.set)
|
|
|
|
|
|
|
|
|
|
# 获取列名
|
|
|
|
|
cursor.execute("SELECT * FROM universities_beijing LIMIT 0")
|
|
|
|
|
cursor.execute("SELECT * FROM universities_beijing LIMIT 0") # 替换为您的表名
|
|
|
|
|
self.columns = [description[0] for description in cursor.description]
|
|
|
|
|
|
|
|
|
|
# 获取数据
|
|
|
|
|
cursor.execute("SELECT * FROM universities_beijing")
|
|
|
|
|
cursor.execute("SELECT * FROM universities_beijing") # 获取所有数据
|
|
|
|
|
self.data = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
# 设置列
|
|
|
|
@ -110,9 +147,10 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
|
|
|
|
|
# 动态设置列和列名
|
|
|
|
|
for column in self.columns:
|
|
|
|
|
self.tree.column(column, anchor=tk.W, width=100, stretch=tk.YES)
|
|
|
|
|
self.tree.column(column, anchor=tk.W, width=50, stretch=tk.YES) # 设置为自适应宽度
|
|
|
|
|
self.tree.heading(column, text=column, anchor=tk.W)
|
|
|
|
|
|
|
|
|
|
# 将 treeview 和滚动条放置到 tree_frame
|
|
|
|
|
self.tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
|
|
|
|
self.vertical_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
|
|
|
|
|
|
|
|
|
@ -134,41 +172,62 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
|
|
|
|
|
def show_university_details(self, event):
|
|
|
|
|
selected_item = self.tree.selection()[0] # 获取选中的行
|
|
|
|
|
university_data = self.tree.item(selected_item, 'values') # 获取行数据
|
|
|
|
|
|
|
|
|
|
if university_data:
|
|
|
|
|
self.detail_window = tk.Toplevel(self) # 创建新窗口
|
|
|
|
|
self.detail_window.title("大学详细信息")
|
|
|
|
|
self.detail_window.geometry("400x300")
|
|
|
|
|
|
|
|
|
|
# 显示大学的其他信息
|
|
|
|
|
detail_label = tk.Label(self.detail_window, text=f"大学名称: {university_data[0]}") # Assuming first column is name
|
|
|
|
|
detail_label.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
additional_info = f"其他信息:\n" # Here you can add more info as needed.
|
|
|
|
|
additional_info_label = tk.Label(self.detail_window, text=additional_info)
|
|
|
|
|
additional_info_label.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
# 添加评论框
|
|
|
|
|
comment_label = tk.Label(self.detail_window, text="添加评论:")
|
|
|
|
|
comment_label.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
self.comment_entry = tk.Entry(self.detail_window)
|
|
|
|
|
self.comment_entry.pack(pady=5)
|
|
|
|
|
|
|
|
|
|
submit_comment_button = tk.Button(self.detail_window, text="提交评论", command=lambda: self.submit_comment(university_data[0]))
|
|
|
|
|
submit_comment_button.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
self.detail_window.protocol("WM_DELETE_WINDOW", self.detail_window.destroy)
|
|
|
|
|
university_data = self.tree.item(selected_item, 'values') # 获取行数据
|
|
|
|
|
with pymysql.connect(host='localhost', user='root', password='123456', database='mynewdb')as connection:
|
|
|
|
|
cursor= connection.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if university_data:
|
|
|
|
|
self.detail_window = tk.Toplevel(self) # 创建新窗口
|
|
|
|
|
self.detail_window.title("大学详细信息")
|
|
|
|
|
self.detail_window.attributes('-fullscreen', True)
|
|
|
|
|
|
|
|
|
|
cursor.execute("SELECT * FROM universities_beijing LIMIT 0") # 替换为您的表名
|
|
|
|
|
columns = [desc[0] for desc in cursor.description]
|
|
|
|
|
tree_detail = ttk.Treeview(self.detail_window, columns=[1,2], show='headings')
|
|
|
|
|
# 显示大学的其他信息
|
|
|
|
|
i=0
|
|
|
|
|
while i < len(columns):
|
|
|
|
|
for detail in university_data:
|
|
|
|
|
tree_detail.insert("","end",values=(columns[i]+":",detail))
|
|
|
|
|
i+=1
|
|
|
|
|
tree_detail.pack(expand=True, fill='both')
|
|
|
|
|
# 添加评论框
|
|
|
|
|
tree_comment=ttk.Treeview(self.detail_window,columns=[1,2,3,4],show='headings')
|
|
|
|
|
tree_comment.column('1',width=300)
|
|
|
|
|
tree_comment.column('2', width=300)
|
|
|
|
|
tree_comment.column('3', width=800)
|
|
|
|
|
tree_comment.column('4',width=200)
|
|
|
|
|
tree_comment.pack(expand=True,fill='both')
|
|
|
|
|
sql="select * FROM comments where university_name=%s Order by comment_time desc"
|
|
|
|
|
cursor.execute(sql,(university_data[0],))
|
|
|
|
|
result = cursor.fetchall()
|
|
|
|
|
for row in result:
|
|
|
|
|
tree_comment.insert("", tk.END, values=row)
|
|
|
|
|
comment_label = tk.Label(self.detail_window, text="添加评论:")
|
|
|
|
|
comment_label.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
self.comment_entry = tk.Entry(self.detail_window)
|
|
|
|
|
self.comment_entry.pack(pady=5)
|
|
|
|
|
|
|
|
|
|
submit_comment_button = tk.Button(self.detail_window, text="提交评论",command=lambda: self.submit_comment(university_data[0]))
|
|
|
|
|
submit_comment_button.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
back_button = tk.Button(self.detail_window, text="返回", command=self.detail_window.destroy)
|
|
|
|
|
back_button.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
|
|
def submit_comment(self, university_name):
|
|
|
|
|
global current_username
|
|
|
|
|
comment = self.comment_entry.get()
|
|
|
|
|
if comment:
|
|
|
|
|
# Store comment in the database (add your SQL query here)
|
|
|
|
|
with pymysql.connect(host='localhost', user='root', password='123456', database='mynewdb') as connection:
|
|
|
|
|
cursor = connection.cursor()
|
|
|
|
|
sql = "INSERT INTO comments (university_name, comment) VALUES (%s, %s)"
|
|
|
|
|
cursor.execute(sql, (university_name, comment))
|
|
|
|
|
comment_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
sql = "INSERT INTO comments (username,university_name, comment,comment_time) VALUES (%s,%s, %s, %s)"
|
|
|
|
|
cursor.execute(sql, (current_username,university_name, comment,comment_time))
|
|
|
|
|
connection.commit()
|
|
|
|
|
|
|
|
|
|
messagebox.showinfo("评论", "评论提交成功")
|
|
|
|
@ -183,22 +242,32 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
self.title("评论界面")
|
|
|
|
|
self.attributes('-fullscreen', True)
|
|
|
|
|
|
|
|
|
|
self.comment_frame = tk.Frame(self)
|
|
|
|
|
|
|
|
|
|
self.comment_frame=tk.Frame(self)
|
|
|
|
|
self.comment_frame.pack(fill=tk.BOTH, expand=True, padx=50, pady=50)
|
|
|
|
|
|
|
|
|
|
self.back_button = tk.Button(self.comment_frame, text="返回", command=self.show_main_window)
|
|
|
|
|
self.back_button.pack(pady=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def search_data(self):
|
|
|
|
|
search_term = self.search1_entry.get() # Fixed to use the correct entry
|
|
|
|
|
search1_term = self.search1_entry.get()
|
|
|
|
|
search2_term = self.search2_entry.get()
|
|
|
|
|
search3_term = self.search3_entry.get()
|
|
|
|
|
search4_term = self.search4_entry.get()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 清空当前Treeview
|
|
|
|
|
self.tree.delete(*self.tree.get_children())
|
|
|
|
|
|
|
|
|
|
# 重新插入符合搜索条件的数据
|
|
|
|
|
for row in self.data:
|
|
|
|
|
if any(search_term in str(value).lower() for value in row):
|
|
|
|
|
self.tree.insert("", tk.END, values=row)
|
|
|
|
|
if any((search1_term in str(value).lower() for value in row)):
|
|
|
|
|
if any((search2_term in str(value).lower() for value in row)):
|
|
|
|
|
if any((search3_term in str(value).lower() for value in row)):
|
|
|
|
|
if any((search4_term in str(value).lower() for value in row)):
|
|
|
|
|
self.tree.insert("", tk.END, values=row)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_register_window(self):
|
|
|
|
|
if self.login_frame:
|
|
|
|
@ -225,24 +294,21 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
self.password_entry = tk.Entry(self.register_frame, show="*")
|
|
|
|
|
self.password_entry.grid(row=1, column=1)
|
|
|
|
|
|
|
|
|
|
self.confirm_password_label = tk.Label(self.register_frame, text="确认密码:")
|
|
|
|
|
self.confirm_password_label = tk.Label(self.register_frame, text="再次输入密码:")
|
|
|
|
|
self.confirm_password_label.grid(row=2, column=0)
|
|
|
|
|
self.confirm_password_entry = tk.Entry(self.register_frame, show="*")
|
|
|
|
|
self.confirm_password_entry.grid(row=2, column=1)
|
|
|
|
|
|
|
|
|
|
self.register_button = tk.Button(self.register_frame, text="注册", command=self.register)
|
|
|
|
|
self.register_button.grid(row=3, columnspan=2, pady=10)
|
|
|
|
|
self.register_button.grid(row=3, column=0)
|
|
|
|
|
|
|
|
|
|
self.back_to_login_button = tk.Button(self.register_frame, text="返回登录", command=self.create_login_window)
|
|
|
|
|
self.back_to_login_button.grid(row=4, columnspan=2)
|
|
|
|
|
self.back_button = tk.Button(self.register_frame, text="返回", command=self.create_login_window)
|
|
|
|
|
self.back_button.grid(row=3, column=1)
|
|
|
|
|
|
|
|
|
|
def create_login_window(self):
|
|
|
|
|
if self.register_frame:
|
|
|
|
|
self.register_frame.pack_forget()
|
|
|
|
|
if self.comment_frame:
|
|
|
|
|
self.comment_frame.pack_forget()
|
|
|
|
|
|
|
|
|
|
self.title("用户登录界面")
|
|
|
|
|
self.title("登录界面")
|
|
|
|
|
sw = self.winfo_screenwidth()
|
|
|
|
|
sh = self.winfo_screenheight()
|
|
|
|
|
Width = 400
|
|
|
|
@ -265,11 +331,18 @@ class MasterChargeSystem(tk.Tk):
|
|
|
|
|
self.password_entry.grid(row=1, column=1)
|
|
|
|
|
|
|
|
|
|
self.login_button = tk.Button(self.login_frame, text="登录", command=self.login)
|
|
|
|
|
self.login_button.grid(row=2, columnspan=2, pady=10)
|
|
|
|
|
self.login_button.grid(row=2, column=0)
|
|
|
|
|
|
|
|
|
|
self.back_button = tk.Button(self.login_frame, text="退出", command=self.quit)
|
|
|
|
|
self.back_button.grid(row=2, column=1)
|
|
|
|
|
|
|
|
|
|
self.register_button = tk.Button(self.login_frame, text="注册", command=self.show_register_window)
|
|
|
|
|
self.register_button.grid(row=3, columnspan=2)
|
|
|
|
|
self.register_button.grid(row=3, column=0)
|
|
|
|
|
|
|
|
|
|
self.deiconify()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Start the application
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
app = MasterChargeSystem()
|
|
|
|
|
app.mainloop()
|
|
|
|
|
app.mainloop()
|