python+tkinter实现学生管理系统

本文实例为大家分享了python+tkinter实现学生管理系统的具体代码,供大家参考,具体内容如下

from tkinter import *
from tkinter.messagebox import *
import sqlite3
from tkinter import ttk

dbstr = "H:\mydb.db"

root = Tk()
root.geometry('700x1000')
root.title('学生管理系统')

Label(root, text="学号:").place(relx=0, rely=0.05, relwidth=0.1)
Label(root, text="姓名:").place(relx=0.5, rely=0.05, relwidth=0.1)
Label(root, text="电话:").place(relx=0, rely=0.1, relwidth=0.1)
Label(root, text="地址:").place(relx=0.5, rely=0.1, relwidth=0.1)

sid = StringVar()
name = StringVar()
phone = StringVar()
address = StringVar()
Entry(root, textvariable=sid).place(relx=0.1, rely=0.05, relwidth=0.37, height=25)
Entry(root, textvariable=name).place(relx=0.6, rely=0.05, relwidth=0.37, height=25)

Entry(root, textvariable=phone).place(relx=0.1, rely=0.1, relwidth=0.37, height=25)
Entry(root, textvariable=address).place(relx=0.6, rely=0.1, relwidth=0.37, height=25)

Label(root, text='学生信息管理', bg='white', fg='red', font=('宋体', 15)).pack(side=TOP, fill='x')

def showAllInfo():
 x = dataTreeview.get_children()
 for item in x:
  dataTreeview.delete(item)
 con = sqlite3.connect(dbstr)
 cur = con.cursor()
 cur.execute("select * from student")
 lst = cur.fetchall()
 for item in lst:
  dataTreeview.insert("", 1, text="line1", values=item)
 cur.close()
 con.close()

def appendInfo():
 if sid.get() == "":
  showerror(title='提示', message='输入不能为空')
 elif name.get() == "":
  showerror(title='提示', message='输入不能为空')
 elif phone.get() == "":
  showerror(title='提示', message='输入不能为空')
 elif address.get() == "":
  showerror(title='提示', message='输入不能为空')
 else:
  x = dataTreeview.get_children()
  for item in x:
   dataTreeview.delete(item)
  list1 = []
  list1.append(sid.get())
  list1.append(name.get())
  list1.append(phone.get())
  list1.append(address.get())
  con = sqlite3.connect(dbstr)
  cur = con.cursor()
  cur.execute("insert into student values(?,?,?,?)", tuple(list1))
  con.commit()
  cur.execute("select * from student")
  lst = cur.fetchall()
  for item in lst:
   dataTreeview.insert("", 1, text="line1", values=item)
  cur.close()
  con.close()

def deleteInfo():
 con = sqlite3.connect(dbstr)
 cur = con.cursor()
 cur.execute("select * from student")
 studentList = cur.fetchall()
 cur.close()
 con.close()
 print(studentList)

 num = sid.get()
 flag = 0
 if num.isnumeric() == False:
  showerror(title='提示', message='删除失败')
 for i in range(len(studentList)):
  for item in studentList[i]:
   if int(num) == item:
    flag = 1
    con = sqlite3.connect(dbstr)
    cur = con.cursor()
    cur.execute("delete from student where id = ?", (int(num),))
    con.commit()
    cur.close()
    con.close()
    break
 if flag == 1:
  showinfo(title='提示', message='删除成功!')
 else:
  showerror(title='提示', message='删除失败')

 x = dataTreeview.get_children()
 for item in x:
  dataTreeview.delete(item)

 con = sqlite3.connect(dbstr)
 cur = con.cursor()
 cur.execute("select * from student")
 lst = cur.fetchall()
 for item in lst:
  dataTreeview.insert("", 1, text="line1", values=item)
 cur.close()
 con.close()

Button(root, text="显示所有信息", command=showAllInfo).place(relx=0.2, rely=0.2, width=100)
Button(root, text="追加信息", command=appendInfo).place(relx=0.4, rely=0.2, width=100)
Button(root, text="删除信息", command=deleteInfo).place(relx=0.6, rely=0.2, width=100)

dataTreeview = ttk.Treeview(root, show='headings', column=('sid', 'name', 'phone', 'address'))
dataTreeview.column('sid', width=150, anchor="center")
dataTreeview.column('name', width=150, anchor="center")
dataTreeview.column('phone', width=150, anchor="center")
dataTreeview.column('address', width=150, anchor="center")

dataTreeview.heading('sid', text='学号')
dataTreeview.heading('name', text='名字')
dataTreeview.heading('phone', text='电话')
dataTreeview.heading('address', text='地址')

dataTreeview.place(rely=0.3, relwidth=0.97)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • python3.6+django2.0开发一套学员管理系统

    1.在pycharm中新建project demo1 添加app01 点击create按钮完成新建 2.在demo项目目录下新建目录static,并在settings.py中追加代码: STATICFILES_DIRS=(os.path.join(BASE_DIR, 'static'),) 3.在setting.py中添加模板路径: TEMPLATES = [ { 'BACKEND': '...', 'DIRS': [os.path.join(BASE_DIR, 'templates'),],

  • python学生信息管理系统

    本文实例为大家分享了python学生信息管理系统的具体代码,供大家参考,具体内容如下 #编译环境为python3 #学生信息管理系统包括基本的信息功能,能够实现学生信息的输入,查询,增添和删除 #基本框架:开始操作菜单,接收输入选项,调用相应的函数实现对应的功能,循环回到开始菜单, #操作菜单: student = [] def studentMeau(): print('-'*30) print('-------学生信息管理系统-------') print(' 1.添加学生信息') prin

  • python Tkinter版学生管理系统

    本文实例为大家分享了python Tkinter版学生管理的具体代码,供大家参考,具体内容如下 Tkinter是python自带的UI包,无需下载,只需要导入 tkinter 文档 //http://effbot.org/tkinterbook//// 文档是英文版本的,可以翻译! 界面效果如下: python的pc端界面还是可以的,较为美观! 页面较为粗狂,为经过专业设计! 系统的对象封装,数据连接使用的是原本控制台版本的! 控制台版本的系统,包含对象封装,数据连接 #导入tkinter 包

  • Python实现GUI学生信息管理系统

    本文实例为大家分享了Python实现GUI学生信息管理系统的具体代码,供大家参考,具体内容如下 项目环境:  软件环境: OS:RedHat6.3                   Lib:Pygtk                   Language:Python                   Support tool:Glade3 项目简述: ①Glade3设计用户的登录窗口,功能主窗口 ②通过Gtk.Builder初始化,载入界面 ③在Mysql.py文件中实现Python操作数

  • Python学生成绩管理系统简洁版

    讲起学生成绩管理系统,从大一C语言的课程设计开始,到大二的C++课程设计都是这个题,最近在学树莓派,好像树莓派常用Python编程,于是学了一波Python,看了一点基本的语法想写点东西练下手. 开发环境:Ubuntu+Python2.7 代码如下: #coding=utf-8 #保存学生信息 studentList=[] def addInfo(name,addr): tempInfo={} tempInfo['name']=name tempInfo['addr']=addr student

  • python实现外卖信息管理系统

    本文为大家分享了python实现外卖信息管理系统的具体代码,供大家参考,具体内容如下 一.需求分析 需求分析包含如下: 1.问题描述 以外卖信息系统管理员身份登陆该系统,实现对店铺信息.派送员信息.客服人员信息.订单信息.配送信息等进行有条件查询以及信息的录入.修改.删除等功能. 2.系统功能描述 (1)信息录入:使用wxpython设计排版编写窗口界面,给出录入信息的接口,通过python语句实现与数据库的连接,从而向数据库中插入相应数据. (2)信息修改:使用wxpython设计排版编写窗口

  • Python实现学生成绩管理系统

    本文实例为大家分享了Python实现学生成绩管理系统的具体代码,供大家参考,具体内容如下 基本功能: 输入并存储学生的信息:通过输入学生的学号.姓名.和分数,然后就可以把数据保存在建立的student文件里面. 打印学生的所有信息:通过一个打印函数就可以把所有的信息打印在屏幕上. 修改学生信息:这个功能首先通过查询功能查询出该学生是否存在,如果存在就对该学生的信息进行修改,如果不存在则返回到主界面. 删除学生信息:该功能是对相应的学生进行删除操作,如果学生存在就查找到进行删除. 按学生成绩进行排

  • python实现图书管理系统

    本文实例为大家分享了python实现图书管理系统的具体代码,供大家参考,具体内容如下 import mysql.connector import sys, os import time import datetime from tkinter import * from tkinter.messagebox import * class Libop: user = 'root' pwd = '' host = 'localhost' db = 'library' data_file = 'mys

  • python实现学生信息管理系统

    继上篇博客Python实现简易通讯录后,我就想写一个复杂点的学生信息管理系统,这次实现的功能有 1.学生信息的录入管理: 2.学生选课操作: 3.学生选课情况查询: 这次仍然用到sqlite3模块.虽然看着挺简单,但是也踩了不少坑,毕竟刚开始实战,有些细节的还需要多多磨炼啊! 好了,废话不多说,直接上代码,欢迎感兴趣的朋友私信讨论~~~ #-*- coding:utf-8 -*- import sqlite3 #打开本地数据库用于存储用户信息 conn = sqlite3.connect('st

  • python图书管理系统

    本文实例为大家分享了python图书管理系统的具体代码,供大家参考,具体内容如下 实现语言:python 图形框架:DTK+2.0 数据库框架:SQLite 3.0 本程序需要以下部件运行: Python2.5.0.GTK+2.16.Pygtk 2.16.PyGobject 2.14.Pycairo 1.4 LibiaryManager.py #!/usr/bin/python # -*- coding: utf-8 -*- import pygtk pygtk.require('2.0') i

随机推荐