前言
Tkinter是python内置的标准GUI库,基于Tkinter实现了简易人员管理系统,所用数据库为Mongodb
代码
时间宝贵!直接上代码!(主要是懒,后续一点点精修8)
from tkinter import *
from tkinter.messagebox import *
from tkinter import ttk
import pymongo
import tkinter as tk
import re
import time
import datetime
import pandas as pd
from tkinter import filedialog
from PIL import ImageTk,Image
import tkinter
#连接数据库
client = pymongo.MongoClient(host="localhost", port=27017)
db = client.sys
col = db.user
#创建窗口
root = Tk()
root.geometry('900x700')
root.title('人员管理系统')
#表头
img =Image.open(r'C:\Users\apple\Desktop\image.jpg')
img = img.resize((900,68),Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
top=Label(root, text='人员管理系统',image=img,fg='black',font=('楷体', 20),compound='center', bitmap='error')
top.pack(ipady=0,side=TOP, fill='x')
#变量
sid = StringVar()
name = StringVar()
age = StringVar()
salary = StringVar()
phone = StringVar()
birthday = StringVar()
#控制函数
def add():
global info
info=Toplevel()
info.title("添加信息")
info.geometry('400x400')
button1=Button(info, text="确认",command=appendInfo,font=("黑体", 12)).place(relx=0.4, rely=0.8, width=100)
Label(info, text="工号:").place(relx=0.2, rely=0.1, relwidth=0.1)
Label(info, text="姓名:").place(relx=0.2, rely=0.2, relwidth=0.1)
Label(info, text="年龄:").place(relx=0.2, rely=0.3, relwidth=0.1)
Label(info, text="薪资:").place(relx=0.2, rely=0.4, relwidth=0.1)
Label(info, text="电话:").place(relx=0.2, rely=0.5, relwidth=0.1)
Label(info, text="生日:").place(relx=0.2, rely=0.6, relwidth=0.1)
text1=Entry(info, textvariable=sid).place(relx=0.3, rely=0.1, relwidth=0.45, height=25)
sid.set("")
text2=Entry(info, textvariable=name).place(relx=0.3, rely=0.2, relwidth=0.45, height=25)
name.set("")
text3=Entry(info, textvariable=age).place(relx=0.3, rely=0.3, relwidth=0.45, height=25)
age.set("")
text4=Entry(info, textvariable=salary).place(relx=0.3, rely=0.4, relwidth=0.45, height=25)
salary.set("")
text5=Entry(info, textvariable=phone).place(relx=0.3, rely=0.5, relwidth=0.45, height=25)
phone.set("")
text6=Entry(info, textvariable=birthday).place(relx=0.3, rely=0.6, relwidth=0.45, height=25)
birthday.set("")
info.bind('<Return>',pas8)
# info.bind_all('<KeyPress-Up>',movetriangle)
# info.bind_all('<KeyPress-Down>',movetriangle)
# info.bind_all('<KeyPress-Left>',movetriangle)
# .bind_all('<KeyPress-Right>',movetriangle)
def pitch_on():
global info
info=Toplevel()
info.title("删除信息")
info.geometry('400x400')
Label(info, text="是否确定删除以下信息",font=('楷体', 15)).place(relx=0.2, rely=0.01, relwidth=0.6)
Label(info, text="工号:").place(relx=0.2, rely=0.1, relwidth=0.1)
Label(info, text="姓名:").place(relx=0.2, rely=0.2, relwidth=0.1)
Label(info, text="年龄:").place(relx=0.2, rely=0.3, relwidth=0.1)
Label(info, text="薪资:").place(relx=0.2, rely=0.4, relwidth=0.1)
Label(info, text="电话:").place(relx=0.2, rely=0.5, relwidth=0.1)
Label(info, text="生日:").place(relx=0.2, rely=0.6, relwidth=0.1)
text1=Entry(info, textvariable=sid,state='disable').place(relx=0.3, rely=0.1, relwidth=0.45, height=25)
sid.set(sf[0])
text2=Entry(info, textvariable=name,state='disable').place(relx=0.3, rely=0.2, relwidth=0.45, height=25)
name.set(sf[1])
text3=Entry(info, textvariable=age,state='disable').place(relx=0.3, rely=0.3, relwidth=0.45, height=25)
age.set(sf[2])
text4=Entry(info, textvariable=salary,state='disable').place(relx=0.3, rely=0.4, relwidth=0.45, height=25)
salary.set(sf[3])
text5=Entry(info, textvariable=phone,state='disable').place(relx=0.3, rely=0.5, relwidth=0.45, height=25)
phone.set(sf[4])
text6=Entry(info, textvariable=birthday,state='disable').place(relx=0.3, rely=0.6, relwidth=0.45, height=25)
birthday.set(sf[5])
button1=Button(info, text="确认",command=deleteInfo).place(relx=0.2, rely=0.8, width=100)
button2=Button(info, text="关闭",command=des).place(relx=0.6, rely=0.8, width=100)
info.bind('<Return>',pas33)
def information2():
global info
info=Toplevel()
info.title("详细信息")
info.</