ADD file via upload

main
pcafzw7pf 6 months ago
parent 596714b2b0
commit f3214c3af6

@ -0,0 +1,76 @@
import tkinter as tk
import mysql.connector
import subprocess # 用于执行外部命令
from PIL import Image, ImageTk # 处理图片
def login():
username = username_entry.get()
password = password_entry.get()
# 连接MySQL数据库
conn = mysql.connector.connect(
host="localhost",
user="root",
password="15975348620",
database="fkchat"
)
# 创建游标
cursor = conn.cursor()
# 查询数据库中是否存在匹配的用户名和密码
cursor.execute("SELECT * FROM users WHERE username = %s AND password = %s", (username, password))
result = cursor.fetchone()
# print(result)
if result:
root.destroy()#关闭ui
subprocess.call('python chat1.py', shell=True)
else:
error_label.config(text="用户名或密码错误")
# 关闭连接
cursor.close()
conn.close()
def register():
root.destroy()
subprocess.call('python register.py', shell=True)
root = tk.Tk()
root.title("召唤下等外国马")
root.geometry("400x400")
# 加载背景图
bg_image = Image.open("p_chatgpt.jpg") # 替换为你的背景图片文件路径
# 在pillow的10.0.0版本中ANTIALIAS方法被删除了使用新的方法LANCZOS即可
bg_image = bg_image.resize((400, 400), Image.LANCZOS) # 调整图片大小以适应窗口
background_img = ImageTk.PhotoImage(bg_image)
background_label = tk.Label(root, image=background_img)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
username_label = tk.Label(root, text="用户名:", bg='white')
username_label.pack(pady=10)
username_entry = tk.Entry(root)
username_entry.pack()
password_label = tk.Label(root, text="密码:")
password_label.pack(pady=10)
password_entry = tk.Entry(root, show="*")
password_entry.pack()
login_button = tk.Button(root, text="登录", command=login)
login_button.pack(pady=10)
register_button = tk.Button(root, text="注册", command=register)
register_button.pack(pady=10)
error_label = tk.Label(root, text="")
error_label.pack()
root.mainloop()
Loading…
Cancel
Save