当前位置: 首页 > news >正文

郑州网站建设seo商业网站建设所用软件

郑州网站建设seo,商业网站建设所用软件,服装网络营销策划书,wordpress出选择题目录 一、tkinter的介绍 二、登陆界面的设计 1、登陆界面完整代码 2、部分代码讲解 3、登录的数据模型设计 4、效果展示 三、学生主界面菜单设计 1、学生主界面菜单设计完整代码 2、 部分代码讲解 3、效果展示 四、数据库的模型设计 欢迎大家进来学习和支持&#xff01…

目录

一、tkinter的介绍

二、登陆界面的设计

1、登陆界面完整代码

2、部分代码讲解

3、登录的数据模型设计

 4、效果展示

三、学生主界面菜单设计

 1、学生主界面菜单设计完整代码

2、 部分代码讲解

 3、效果展示

四、数据库的模型设计


 

欢迎大家进来学习和支持!!!

今天主要带来的是使用tkinter来制作一期学生信息管理系统

一、tkinter的介绍

tkinter就是python语言里面用来制作一个GUI界面的一个包,这里长话短说,不做过多的言语上的阐述,想了解更多可以点击下面的链接

tkinter官网教程

二、登陆界面的设计

我们开始编写代码的之前,我们的自己先了解一些关于tkinter中的一些组件的使用和方法 

1、登陆界面完整代码

"""
Ryan 2024.7.28
登陆页面的制作
"""
import tkinter as tk
from tkinter import messagebox
from db import db
from mainPage import mainPageclass loginFarme(object):def __init__(self, window):self.window = windowself.window.geometry("300x180")self.window.title("登录界面")# 创建变量对象self.username = tk.StringVar()self.password = tk.StringVar()# 用于后面进行页面换页用的self.page = tk.Frame(window)self.page.pack()# 再page里面布局tk.Label(self.page).grid(row=0, column=0)tk.Label(self.page, text="账户:", font=28).grid(row=1, column=1)# textvariable:文本变量tk.Entry(self.page, textvariable=self.username).grid(row=1, column=2)tk.Label(self.page, text="密码:", font=28).grid(row=3, column=1, pady=10)tk.Entry(self.page, textvariable=self.password).grid(row=3, column=2)tk.Button(self.page, text="登录", font=28, command=self.login).grid(row=5, column=1, pady=10)tk.Button(self.page, text="退出", font=28, command=self.page.quit).grid(row=5, column=2)# 登录功能def login(self):name = self.username.get()pwd = self.password.get()flag, message = db.checkLogin(name, pwd)if flag:# 销毁第一页self.page.destroy()# 重新给页面添加内容mainPage(self.window)else:messagebox.showwarning(title="警告", message=message)if __name__ == '__main__':window = tk.Tk()loginFarme(window)window.mainloop()

2、部分代码讲解

对于loginFarme类的讲解:

        这个属于类的初始化函数部分,给登录界面创建界面组件用 

    def __init__(self, window):self.window = windowself.window.geometry("300x180")self.window.title("登录界面")# 创建变量对象self.username = tk.StringVar()self.password = tk.StringVar()# 用于后面进行页面换页用的self.page = tk.Frame(window)self.page.pack()# 再page里面布局tk.Label(self.page).grid(row=0, column=0)tk.Label(self.page, text="账户:", font=28).grid(row=1, column=1)# textvariable:文本变量tk.Entry(self.page, textvariable=self.username).grid(row=1, column=2)tk.Label(self.page, text="密码:", font=28).grid(row=3, column=1, pady=10)tk.Entry(self.page, textvariable=self.password).grid(row=3, column=2)tk.Button(self.page, text="登录", font=28, command=self.login).grid(row=5, column=1, pady=10)tk.Button(self.page, text="退出", font=28, command=self.page.quit).grid(row=5, column=2)

         这一部分是为了实现登陆的功能和警告信息,这里面调用了db这个类对象checkLogin方法,是为了检查账户密码的正确性,这个类对象会在后面定义,这里的mainPage方法是调用了mainPage.py文件里的方法,为了登录成功后进入到学生管理系统主界面

 # 登录功能def login(self):name = self.username.get()pwd = self.password.get()flag, message = db.checkLogin(name, pwd)if flag:# 销毁第一页self.page.destroy()# 重新给页面添加内容mainPage(self.window)else:messagebox.showwarning(title="警告", message=message)

         这个代码块想必大家都很熟悉,这个代码块主要是为了检查该程序是否能够在这个文件里运行,这里的tk.Tk()和mainloop()方法是打开窗口界面和循环显示窗口界面的功能

if __name__ == '__main__':window = tk.Tk()loginFarme(window)window.mainloop()

3、登录的数据模型设计

        这里是主要封装了一个对于登录信息的检查,这里没有用到数据库,而是自己创建了一个json的数据模型来代替,这个就是上面所说到的checkLogin()方法的定义代码 

"""
Ryan 2024.7.28
建立登录的数据模型
"""
import jsonclass mySqlDatabases(object):def __init__(self):with open('student.json', mode='r', encoding='utf-8') as f:text = f.read()self.students = json.loads(text)f.close()def checkLogin(self, username, password):for student in self.students:if username == student['username']:if password == student['password']:return True, '登陆成功'else:return False, '登陆失败,密码不存在'return False, '登陆失败,用户名不存在'# 实例化类对象
db = mySqlDatabases()
if __name__ == '__main__':print(db.checkLogin('admin', '123456'))

 4、效果展示

三、学生主界面菜单设计

接下来我们设计好登录界面后,就是进入到学生的主界面设计 

 1、学生主界面菜单设计完整代码

"""
Ryan 2024.7.28
学生页面的制作
"""
import tkinter as tkclass mainPage(object):# window:tk.Tk只作为一个提示是TK对象,写完这个就可以显示方法提示def __init__(self, window: tk.Tk):self.window = windowself.window.geometry('600x400')self.window.title('学生管理系统 V0.0.1')self.createPage()def createMenu(self):self.aboutFrame = tk.Frame(self.window)tk.Label(self.aboutFrame, text='关于作品:本作品是tkinter制作的').pack()tk.Label(self.aboutFrame, text='关于作者:Ryan').pack()tk.Label(self.aboutFrame, text='版权所有:Ryan').pack()self.changeFrame = tk.Frame(self.window)tk.Label(self.changeFrame, text='修改页面').pack()self.deleteFrame = tk.Frame(self.window)tk.Label(self.deleteFrame, text='删除页面').pack()self.searchFrame = tk.Frame(self.window)tk.Label(self.searchFrame, text='搜索页面').pack()self.insertFrame = tk.Frame(self.window)tk.Label(self.insertFrame, text='录入页面').pack()def createPage(self):self.createMenu()menuBar = tk.Menu(self.window)menuBar.add_command(label='录入', command=self.showInsert)menuBar.add_command(label='查询', command=self.showSearch)menuBar.add_command(label='删除', command=self.showDelete)menuBar.add_command(label='修改', command=self.showChange)menuBar.add_command(label='关于', command=self.showAbout)# 将menuBar添加窗口中self.window['menu'] = menuBardef showAbout(self):self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.aboutFrame.pack()def showChange(self):self.aboutFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.changeFrame.pack()def showDelete(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.deleteFrame.pack()def showSearch(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.insertFrame.pack_forget()self.searchFrame.pack()def showInsert(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack()if __name__ == '__main__':window = tk.Tk()mainPage(window)window.mainloop()

2、 部分代码讲解

 以下主要是针对mainPage类的讲解:

        这里面的createPage函数是添加界面中的菜单按钮,command是当按钮被点击的时候会触发的事件

    def createPage(self):self.createMenu()menuBar = tk.Menu(self.window)menuBar.add_command(label='录入', command=self.showInsert)menuBar.add_command(label='查询', command=self.showSearch)menuBar.add_command(label='删除', command=self.showDelete)menuBar.add_command(label='修改', command=self.showChange)menuBar.add_command(label='关于', command=self.showAbout)# 将menuBar添加窗口中self.window['menu'] = menuBar

        以下是菜单被点击的时候所触发的函数方法 ,这里面的pack_forget方法是为了清除界面添加的内容,防止内容会一直保留到界面当中

    def showAbout(self):self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.aboutFrame.pack()def showChange(self):self.aboutFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.changeFrame.pack()def showDelete(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack_forget()self.deleteFrame.pack()def showSearch(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.insertFrame.pack_forget()self.searchFrame.pack()def showInsert(self):self.aboutFrame.pack_forget()self.changeFrame.pack_forget()self.deleteFrame.pack_forget()self.searchFrame.pack_forget()self.insertFrame.pack()

 3、效果展示

当你点击下面不同菜单的时候,会进入到不同的页面 

 

四、数据库的模型设计

采用json格式去设计数据模块,后期会用上数据库的连结 

[{"username": "admin","password": "123456"},{"username": "Ryan","password": "123456"}
]

 今天的分享就是这样了,下次带来关于学生信息管理系统的进一步页面设计。

 

 

 

 

http://www.yayakq.cn/news/840764/

相关文章:

  • 扁平化网站设计欣赏济南房产信息网站官网
  • 汕尾建设网站首页个人可以做网站么
  • ps模板网站推荐成都专业网站建设机构
  • 自助搭建网站南阳seo招聘
  • 做网站建设销售汉字域名网站
  • 优化大师官方网站个人做电梯网站
  • 购物网站管理系统佛山网站建设哪家评价高
  • 中国建设会计协会网站WordPress评论区嵌套层样式
  • 南通住房和城乡建设厅网站wordpress修改文章点赞数
  • 建站流程主要有哪些网站开发价钱
  • 个人网站模板响应式福州企业网站推广定制
  • 企业网站建设知名网站建设的方法有哪些
  • 免费建造网站东家乐装修公司怎么样
  • 怎么做网站vip并且收费企业网站建设的三个核心问题
  • 广东网站开发网站制作器
  • 网站建设的资源哪里弄阿坝网页设计公司
  • 做网站好多钱联通网站自主备案系统
  • 甘肃省住房和城乡建设厅网站天津做网站的公司排名
  • wordpress网站白屏怎么创建小程序
  • 买别人做的网站能盗回吗给网站栏目页做反链好吗
  • 国家和城乡建设部网站十大黄台软件app下载
  • 做网站上海公司舆情分析
  • 南京网站设计搭建公司wordpress验证码注册
  • 广西网站建设价格多少owasp+网站开发
  • 青岛网站设计建立公司免费做问卷的网站
  • 影视传媒广告公司网站模板前端做网站需要的技能
  • 住建部城乡建设网站als冰桶挑战赛的网络营销方式
  • 网站建设公司有多少家东莞市朝阳信息网络有限公司
  • 深圳外贸网站推广找客户资源的软件
  • 做手机旅游网站wordpress评论框增强