|
|
|
@ -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()
|
|
|
|
|