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()
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为了实现Python图书管理系统GUI界面,我们可以使用wxPython和wxGlade。wxPython是一个Python的GUI工具包,而wxGlade是一个wxPython支持的GUI编辑器。下面是实现Python图书管理系统GUI界面的步骤: 1.安装wxPython和wxGlade。可以使用pip安装wxPython,使用以下命令安装wxGlade: ```shell pip install wxglade ``` 2.使用wxGlade创建GUI界面。打开wxGlade,选择“File”->“New”,选择“wx.Frame”作为顶级窗口,然后在“Attributes”选项卡中设置窗口的属性,例如标题、大小等。接下来,使用“Widgets”选项卡中的控件工具创建所需的控件,例如按钮、文本框等。最后,使用“Events”选项卡中的事件工具为控件添加事件处理程序。 3.使用wxPythonGUI界面Python代码集成。在wxGlade中保存GUI界面文件,然后使用以下代码将其与Python代码集成: ```python import wx class MyFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title="My Title", pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHints(wx.DefaultSize, wx.DefaultSize) bSizer = wx.BoxSizer(wx.VERTICAL) self.m_button1 = wx.Button(self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0) bSizer.Add(self.m_button1, 0, wx.ALL, 5) self.m_textCtrl1 = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0) bSizer.Add(self.m_textCtrl1, 0, wx.ALL, 5) self.SetSizer(bSizer) self.Layout() self.Centre(wx.BOTH) # Connect Events self.m_button1.Bind(wx.EVT_BUTTON, self.OnButton1Click) def __del__(self): pass # Virtual event handlers, overide them in your derived class def OnButton1Click(self, event): event.Skip() if __name__ == "__main__": app = wx.App(False) frame = MyFrame(None) frame.Show(True) app.MainLoop() ``` 在上面的代码中,我们创建了一个名为“MyFrame”的类,该类继承自wx.Frame类,并包含GUI界面中的所有控件。我们还为按钮添加了一个事件处理程序。 4.将Python代码与图书管理系统集成。在上面的代码中,我们可以添加图书管理系统的代码,例如查询图书、添加图书、删除图书等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值