parent
8697fe3501
commit
540e3e29ca
@ -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()
|
Loading…
Reference in new issue