Python登录注册界面Thinter,Python登录注册系统介绍
在Python中,可以使用Tkinter库创建一个简单的登录注册界面。以下是一个简单的示例代码:
import tkinter as tk
from tkinter import messagebox
def login():
username = entry_username.get()
password = entry_password.get()
if username == "user" and password == "pass":
messagebox.showinfo("Success", "Login successful!")
else:
messagebox.showerror("Error", "Invalid username or password.")
def register():
username = entry_username.get()
password = entry_password.get()
confirm_password = entry_confirm_password.get()
if password == confirm_password:
messagebox.showinfo("Success", "Registration successful!")
else:
messagebox.showerror("Error", "Passwords do not match.")
root = tk.Tk()
root.title("Login/Register System")
# 登录界面
frame_login = tk.Frame(root)
frame_login.pack()
label_username = tk.Label(frame_login, text="Username")
label_username.pack(side=tk.LEFT)
entry_username = tk.Entry(frame_login)
entry_username.pack(side=tk.LEFT)
label_password = tk.Label(frame_login, text="Password")
label_password.pack(side=tk.LEFT)
entry_password = tk.Entry(frame_login, show="*")
entry_password.pack(side=tk.LEFT)
button_login = tk.Button(frame_login, text="Login", command=login)
button_login.pack(side=tk.LEFT)
# 注册界面
frame_register = tk.Frame(root)
frame_register.pack()
label_username_register = tk.Label(frame_register, text="Username")
label_username_register.pack(side=tk.LEFT)
entry_username_register = tk.Entry(frame_register)
entry_username_register.pack(side=tk.LEFT)
label_password_register = tk.Label(frame_register, text="Password")
label_password_register.pack(side=tk.LEFT)
entry_password_register = tk.Entry(frame_register, show="*")
entry_password_register.pack(side=tk.LEFT)
label_confirm_password_register = tk.Label(frame_register, text="Confirm Password")
label_confirm_password_register.pack(side=tk.LEFT)
entry_confirm_password_register = tk.Entry(frame_register, show="*")
entry_confirm_password_register.pack(side=tk.LEFT)
button_register = tk.Button(frame_register, text="Register", command=register)
button_register.pack(side=tk.LEFT)
root.mainloop()
这段代码创建了一个简单的登录注册界面,用户可以在输入框中输入
评论已关闭