Python3.11系统登陆GUI界面源码分享

这也是我自己拿来练手的项目,有 v1.0版和 v2.0版,等于在不断的完善, v1.0版仅仅只是一个登陆界面的外壳,但是 v2.0增加了账号密码以及验证码的校验,大家可以根据自己需要自取。

完整版系统链接:

学生信息管理系统源码分享(Python 3.11)

v1.0版本登陆界面长这样:
在这里插入图片描述
觉得可以用的小伙伴可以直接拿源码过去用,只要 python 版本对应,应该可以直接跑出来,甚至不用改一点。可以用的小伙伴记得点点赞和收藏加评论!这是给博主我最大的鼓励,有鼓励才会多更!

# v1.0 源码分享
import tkinter as tk
from tkinter import StringVar
import random

# 创建一个根窗口
root = tk.Tk()

# 编辑窗口标题
root.title("学生信息管理系统 v2.0")

# 设置窗口大小
root.geometry('300x180')

# 布局 root 窗口
# Label() 显示模块,第一个参数表示显示的窗口名, text 显示文字
# Entry() 输入模块
ID = tk.Label(root, text="账号:")
ID.place(relx=0.2, rely=0.2, anchor='center')
text1 = tk.Entry(root)
text1.place(relx=0.5, rely=0.2, anchor='center', width=150, height=25)
password = tk.Label(root, text="密码:")
password.place(relx=0.2, rely=0.4, anchor='center')
text2 = tk.Entry(root)
text2.place(relx=0.5, rely=0.4, anchor='center', width=150, height=25)

# 验证码窗口及获取按钮
def creatAuthCode():
    res1=""
    res2=""
    res3=""
    for i in range(2):
        num = random.randint(0,9)
        res1 += str(num)
        num = random.randint(65,91)
        res2 += str(chr(num))
        num = random.randint(97,123)
        res3 += str(chr(num))
        string = str(res1+res2+res3)
        txt.set(string)
code = tk.Label(root, text="验证码:")
code.place(relx=0.22, rely=0.6, anchor='center')
code = tk.Entry(root)
code.place(relx=0.48, rely=0.6, anchor='center', width=100, height=25)
txt = StringVar()
txt.set("获取验证码")
codestr = tk.Button(root, textvariable=txt, command=creatAuthCode, fg="white", bg="black")
codestr.place(relx=0.8, rely=0.6, anchor='center')

# Button 按钮
enter = tk.Button(root, text="登录")
enter.place(relx=0.35, rely=0.8, anchor='center')
back = tk.Button(root, text='退出')
back.place(relx=0.55, rely=0.8, anchor='center')

# 显示根窗口
root.mainloop()

# v2.0 源码分享,用户名:admin, 密码:123456

# 定义一个窗口对象
root = tk.Tk()

# 创建一个登陆页面
# Frame 参数:bd 是边框宽度,relief 是边框类型,参数可以是"raised", "sunken", "flat", "ridge", "solid", "groove"
login_frame = tk.Frame(height=4, bd=5, relief="ridge")
login_frame.place(width=300, height=180)

# 编辑窗口标题
root.title("学生信息管理系统 v2.0")

# 设置窗口大小
root.geometry('300x180')

# 用于获取在登陆界面输入的用户名和密码,以便核对是否正确
username = tk.StringVar()
password = tk.StringVar()
code_input = tk.StringVar()
code_check = ""

# 布局 login_frame 窗口
# Label() 显示模块,第一个参数表示显示的窗口名, text 显示文字
# Entry() 输入模块
# 账号框
ID = tk.Label(login_frame, text="账号:")
ID.place(relx=0.2, rely=0.2, anchor='center')
text1 = tk.Entry(login_frame, textvariable=username)
text1.place(relx=0.5, rely=0.2, anchor='center', width=150, height=25)

# 密码框
pwd = tk.Label(login_frame, text="密码:")
pwd.place(relx=0.2, rely=0.4, anchor='center')
text2 = tk.Entry(login_frame, textvariable=password)
text2.place(relx=0.5, rely=0.4, anchor='center', width=150, height=25)

# 验证码窗口及获取按钮
def creatAuthCode():
    global code_check
    res1 = ""
    res2 = ""
    res3 = ""
    for i in range(2):
        num = random.randint(0,9)
        res1 += str(num)
        num = random.randint(65,91)
        res2 += str(chr(num))
        num = random.randint(97,123)
        res3 += str(chr(num))
        string = str(res1+res2+res3)
        txt.set(string)
        code_check = string
code = tk.Label(login_frame, text="验证码:")
code.place(relx=0.22, rely=0.6, anchor='center')
code = tk.Entry(login_frame, textvariable=code_input)
code.place(relx=0.48, rely=0.6, anchor='center', width=100, height=25)
txt = StringVar()
txt.set("获取验证码")
codestr = tk.Button(login_frame, textvariable=txt, command=creatAuthCode, fg="white", bg="black")
codestr.place(relx=0.8, rely=0.6, anchor='center')

# 点击登陆,校验参数
def check_login():
    if username.get() == 'admin' and password.get() == '123456' and code_input.get() == code_check:
        print("登陆成功")
        # 换页
        login_frame.destroy()
    elif username.get() != 'admin' or password.get() != '123456':
        print("用户名或密码错误!")
    elif username.get() == 'admin' and password.get() == '123456' and code_input.get() != code_check:
        print("验证码错误!")
    else:
        print("登陆失败")

# 登陆按钮
enter = tk.Button(login_frame, text="登录", command=check_login)
enter.place(relx=0.35, rely=0.8, anchor='center')

# 退出按钮
back = tk.Button(login_frame, text='退出', command=login_frame.quit)
back.place(relx=0.55, rely=0.8, anchor='center')

# 显示根窗口
root.mainloop()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值