'commit005'

main
CriptDit 6 months ago
parent a6a598511e
commit c70e54a028

@ -2,6 +2,7 @@ import tkinter as tk
from tkinter import messagebox
from TrialRecommend.LoginCheck import login_check
from Main import Mainpage
import mysql.connector
class Login_page():
@ -19,11 +20,41 @@ class Login_page():
tk.Entry(self.page,textvariable=self.username).grid(row=1, column=2)
tk.Label(self.page, text='密码:').grid(row=2, column=1,pady=10)
tk.Entry(self.page,textvariable=self.password,show='*').grid(row=2, column=2)
tk.Button(self.page,text='登录',command=self.check).grid(row=3, column=1,pady=10)
tk.Button(self.page,text='退出',command=self.page.quit).grid(row=3, column=3,pady=10)
tk.Button(self.page,text='登录',command=self.check,width=10,fg='green').grid(row=3, column=1,pady=10)
tk.Button(self.page,text='注册',width=10,command=self.register).grid(row=3, column=2,pady=10)
tk.Button(self.page,text='退出',command=self.page.quit,width=10,fg='red').grid(row=3, column=3,pady=10)
self.center_window() # 调用函数来居中窗口
self.root.title('旅游推荐系统登录界面')
def register(self):
if self.username.get() == '' or self.password.get() == '':
messagebox.showinfo(message='用户名或密码不能为空')
else:
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="A121023020309a",
database="trial"
)
sql = 'INSERT INTO trial.user (id, psw) VALUES (%s, %s)'
cursor = db.cursor()
success = 'true'
try:
cursor.execute(sql, (str(self.username.get()), str(self.password.get())))
db.commit()
except db.Error as e:
print(f"An error occurred: {e}")
db.rollback()
messagebox.showinfo("Error", "注册失败!")
success = 'false'
finally:
# 确保cursor关闭释放资源
cursor.close()
if success == 'true':
messagebox.showinfo('提示', '注册成功!')
def check(self):
name = self.username.get()
psw = self.password.get()

@ -10,6 +10,7 @@ from PIL import Image, ImageTk
from TrialRecommend import DataRequest, Notes_Request
import func_collec
import dis_collect
class Mainpage:
def __init__(self,master,name):
self.content = ''
@ -73,7 +74,7 @@ class Mainpage:
self.btn_liked = tk.Button(self.page, text='收藏攻略', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.func_collect)
self.btn_liked.place(relx=0.9, rely=0.2, relheight=0.05, relwidth=0.1)
self.btn_dis_liked = tk.Button(self.page, text='取消收藏', bg='#D7EFFF',font=('SimHei',15,'bold'))
self.btn_dis_liked = tk.Button(self.page, text='取消收藏', bg='#D7EFFF',font=('SimHei',15,'bold'),command=self.func_discollect)
self.btn_dis_liked.place(relx=0.9, rely=0.3, relheight=0.05, relwidth=0.1)
self.lable_like=tk.Label(self.page,text='喜欢人数:'+self.likes,font=('SimHei',15,'bold'))
@ -390,6 +391,9 @@ class Mainpage:
else:
messagebox.showinfo('提示','请先搜索')
def func_discollect(self):
dis_collect.dis_collec(self.user,self.current_data_index)
if __name__ == '__main__':
root = tk.Tk()
Mainpage(master=root,name='Null')

@ -0,0 +1,36 @@
import csv
import mysql.connector
from tkinter import messagebox
def dis_collec(user,data_index):
id=''
with open('TrialRecommend/data.csv', 'r', encoding='utf-8', newline='') as file:
reader = csv.reader(file)
index=0
for row in reader:
if index == data_index:
id=row[0]
index=index+1
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="A121023020309a",
database="trial"
)
sql='DELETE FROM collections WHERE user_id = %s AND essay_id = %s'
cursor=db.cursor()
success='true'
try:
cursor.execute(sql, (user, id))
db.commit()
except db.Error as e:
print(f"An error occurred: {e}")
db.rollback()
messagebox.showinfo("Error", "取消收藏失败!")
success='false'
finally:
# 确保cursor关闭释放资源
cursor.close()
if success == 'true':
messagebox.showinfo('提示','取消收藏成功!')

@ -34,3 +34,4 @@ def collec(user,data_index):
cursor.close()
if success == 'true':
messagebox.showinfo('提示','收藏成功!')

@ -0,0 +1,62 @@
import tkinter as tk
from tkinter import messagebox
import mysql.connector
class Register():
def __init__(self):
self.page = tk.Tk()
self.username=tk.StringVar()
self.password=tk.StringVar()
tk.Label(self.page).grid(row=0, column=0)
tk.Label(self.page, text='账户:').grid(row=1, column=1, pady=10)
tk.Entry(self.page, textvariable=self.username).grid(row=1, column=2)
tk.Label(self.page, text='密码:').grid(row=2, column=1, pady=10)
tk.Entry(self.page, textvariable=self.password).grid(row=2, column=2)
tk.Button(self.page, text='确定', command=self.check, width=10, fg='green').grid(row=3, column=1, pady=10)
tk.Button(self.page, text='退出', command=self.quit, width=10, fg='red').grid(row=3, column=3, pady=10)
self.center_window() # 调用函数来居中窗口
self.page.title('旅游推荐系统注册界面')
self.page.mainloop()
def quit(self):
self.page.destroy()
def check(self):
if self.username.get() == '' or self.password.get() == '':
messagebox.showinfo(message='用户名或密码不能为空')
else:
db = mysql.connector.connect(
host="localhost",
user="root",
passwd="A121023020309a",
database="trial"
)
sql = 'INSERT INTO trial.user (id, psw) VALUES (%s, %s)'
cursor = db.cursor()
success = 'true'
try:
cursor.execute(sql, (str(self.username.get()), str(self.password.get())))
db.commit()
except db.Error as e:
print(f"An error occurred: {e}")
db.rollback()
messagebox.showinfo("Error", "注册失败!")
success = 'false'
finally:
# 确保cursor关闭释放资源
cursor.close()
if success == 'true':
messagebox.showinfo('提示', '注册成功!')
self.page.destroy()
def center_window(self, width=400, height=200):
# 获取屏幕宽度和高度
screen_width = self.page.winfo_screenwidth()
screen_height = self.page.winfo_screenheight()
# 计算窗口的左上角应该放置的位置
left = (screen_width / 2) - (width / 2)
top = (screen_height / 2) - (height / 2)
# 设置窗口的位置和大小
self.page.geometry("{0}x{1}+{2}+{3}".format(width, height, int(left), int(top)))
Loading…
Cancel
Save