From 540e3e29caace4134a22c5add060e1d662259235 Mon Sep 17 00:00:00 2001 From: pcafzw7pf <3033465407@qq.com> Date: Fri, 31 May 2024 15:09:11 +0800 Subject: [PATCH] ADD file via upload --- fake_chat/register.py | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 fake_chat/register.py diff --git a/fake_chat/register.py b/fake_chat/register.py new file mode 100644 index 0000000..ca4ec14 --- /dev/null +++ b/fake_chat/register.py @@ -0,0 +1,59 @@ +import tkinter as tk +import mysql.connector +import time + +def register(): + 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("INSERT INTO users (username, password) VALUES (%s, %s)", (username, password)) + conn.commit() + + cursor.close() + conn.close() + + success_label.config(text="注册成功") + + time.sleep(3) # 延时3秒 + + root.destroy() # 关闭注册页面 + + # 跳转回登录页面 + import subprocess + subprocess.call('python login.py', shell=True) + +root = tk.Tk() +root.title("用户注册") +root.geometry("300x200") + +username_label = tk.Label(root, text="用户名:") +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() + +register_button = tk.Button(root, text="注册", command=register) +register_button.pack(pady=10) + +success_label = tk.Label(root, text="") +success_label.pack() + +root.mainloop() \ No newline at end of file