|
|
@ -2,392 +2,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
# Press Shift+F10 to execute it or replace it with your code.
|
|
|
|
# Press Shift+F10 to execute it or replace it with your code.
|
|
|
|
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
|
|
|
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
|
|
|
|
from tkinter import *
|
|
|
|
|
|
|
|
from tkinter import font
|
|
|
|
|
|
|
|
from tkinter import messagebox
|
|
|
|
def print_hi(name):
|
|
|
|
from os import path
|
|
|
|
# Use a breakpoint in the code line below to debug your script.
|
|
|
|
from os import remove
|
|
|
|
from tkinter import messagebox
|
|
|
|
|
|
|
|
import tkinter as tk
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info_list = []
|
|
|
|
class PopupWindow(object):
|
|
|
|
window = tk.Tk()
|
|
|
|
# 初始化构造及添加组件到弹出框
|
|
|
|
window.title('员工管理系统')
|
|
|
|
def __init__(self, master, main_window, title, contact=None):
|
|
|
|
window.geometry('300x300')
|
|
|
|
self.main_window = main_window
|
|
|
|
|
|
|
|
top = self.top = Toplevel(master)
|
|
|
|
staff_title = tk.Label(window, text='欢迎来到员工管理系统', bg='yellow', font=6)
|
|
|
|
top.title(title)
|
|
|
|
staff_title.pack()
|
|
|
|
top.resizable(False, False)
|
|
|
|
|
|
|
|
w = 280
|
|
|
|
def add_staff_info(): # 添加
|
|
|
|
h = 500
|
|
|
|
|
|
|
|
top.geometry('%dx%d+%d+%d' % (w, h, (ws - w) / 2, (hs - h) / 2))
|
|
|
|
def add_ok_info(): # 添加完成按钮
|
|
|
|
top.bind('<Escape>', lambda event: top.destroy())
|
|
|
|
|
|
|
|
|
|
|
|
new_info_dict = dict()
|
|
|
|
m_font = font.Font(size=16)
|
|
|
|
|
|
|
|
l = Label(top, text="编号:", font=m_font)
|
|
|
|
nn = new_name.get()
|
|
|
|
l.pack(side=TOP, pady=5)
|
|
|
|
ns = new_sex.get()
|
|
|
|
self.e1 = Entry(top)
|
|
|
|
na = new_age.get()
|
|
|
|
self.e1.pack(side=TOP, padx=16, ipady=3, fill=X)
|
|
|
|
nb = new_branch.get()
|
|
|
|
self.e1.focus()
|
|
|
|
np = new_phone.get()
|
|
|
|
if contact is not None:
|
|
|
|
|
|
|
|
self.e1.insert(0, contact.number)
|
|
|
|
new_info_dict['姓名'] = nn
|
|
|
|
|
|
|
|
new_info_dict['性别'] = ns
|
|
|
|
l2 = Label(top, text="姓名:", font=m_font)
|
|
|
|
new_info_dict['年龄'] = na
|
|
|
|
l2.pack(side=TOP, pady=5)
|
|
|
|
new_info_dict['部门'] = nb
|
|
|
|
self.e2 = Entry(top)
|
|
|
|
new_info_dict['手机号码'] = np
|
|
|
|
self.e2.pack(side=TOP, padx=16, ipady=3, fill=X)
|
|
|
|
|
|
|
|
if contact is not None:
|
|
|
|
info_list.append(new_info_dict)
|
|
|
|
self.e2.insert(0, contact.name)
|
|
|
|
add_window.destroy()
|
|
|
|
|
|
|
|
tk.messagebox.showinfo(title='提示', message='添加成功!')
|
|
|
|
l2 = Label(top, text="性别:", font=m_font)
|
|
|
|
|
|
|
|
l2.pack(side=TOP, pady=5)
|
|
|
|
new_name = tk.StringVar()
|
|
|
|
self.e3 = Entry(top)
|
|
|
|
new_sex = tk.StringVar()
|
|
|
|
self.e3.pack(side=TOP, padx=16, ipady=3, fill=X)
|
|
|
|
new_age = tk.StringVar()
|
|
|
|
if contact is not None:
|
|
|
|
new_branch = tk.StringVar()
|
|
|
|
self.e3.insert(0, contact.sex)
|
|
|
|
new_phone = tk.StringVar()
|
|
|
|
|
|
|
|
|
|
|
|
l2 = Label(top, text="出生日期:", font=m_font)
|
|
|
|
add_window = tk.Toplevel(window)
|
|
|
|
l2.pack(side=TOP, pady=5)
|
|
|
|
add_window.title('添加信息')
|
|
|
|
self.e4 = Entry(top)
|
|
|
|
add_window.geometry('300x300')
|
|
|
|
self.e4.pack(side=TOP, padx=16, ipady=3, fill=X)
|
|
|
|
|
|
|
|
if contact is not None:
|
|
|
|
tk.Label(add_window, text='姓 名:').place(x=10, y=10)
|
|
|
|
self.e4.insert(0, contact.birth)
|
|
|
|
entry_new_name = tk.Entry(add_window, textvariable=new_name)
|
|
|
|
|
|
|
|
entry_new_name.place(x=80, y=10)
|
|
|
|
l2 = Label(top, text="入职时间:", font=m_font)
|
|
|
|
|
|
|
|
l2.pack(side=TOP, pady=5)
|
|
|
|
tk.Label(add_window, text='性 别:').place(x=10, y=40)
|
|
|
|
self.e5 = Entry(top)
|
|
|
|
entry_new_name = tk.Entry(add_window, textvariable=new_sex)
|
|
|
|
self.e5.pack(side=TOP, padx=16, ipady=3, fill=X)
|
|
|
|
entry_new_name.place(x=80, y=40)
|
|
|
|
if contact is not None:
|
|
|
|
|
|
|
|
self.e5.insert(0, contact.entry_time)
|
|
|
|
tk.Label(add_window, text='年 龄:').place(x=10, y=70)
|
|
|
|
|
|
|
|
entry_new_name = tk.Entry(add_window, textvariable=new_age)
|
|
|
|
l2 = Label(top, text="职位:", font=m_font)
|
|
|
|
entry_new_name.place(x=80, y=70)
|
|
|
|
l2.pack(side=TOP, pady=5)
|
|
|
|
|
|
|
|
self.e6 = Entry(top)
|
|
|
|
tk.Label(add_window, text='部 门:').place(x=10, y=100)
|
|
|
|
self.e6.pack(side=TOP, padx=16, ipady=3, fill=X)
|
|
|
|
entry_new_name = tk.Entry(add_window, textvariable=new_branch)
|
|
|
|
if contact is not None:
|
|
|
|
entry_new_name.place(x=80, y=100)
|
|
|
|
self.e6.insert(0, contact.position)
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(add_window, text='手机号码:').place(x=10, y=130)
|
|
|
|
l2 = Label(top, text="工资:", font=m_font)
|
|
|
|
entry_new_name = tk.Entry(add_window, textvariable=new_phone)
|
|
|
|
l2.pack(side=TOP, pady=5)
|
|
|
|
entry_new_name.place(x=80, y=130)
|
|
|
|
self.e7 = Entry(top)
|
|
|
|
|
|
|
|
self.e7.pack(side=TOP, padx=16, ipady=3, fill=X)
|
|
|
|
add_ok_button = tk.Button(add_window, text='完成', command=add_ok_info)
|
|
|
|
if contact is not None:
|
|
|
|
add_ok_button.place(x=100, y=200)
|
|
|
|
self.e7.insert(0, contact.salary)
|
|
|
|
|
|
|
|
|
|
|
|
def show_staff_info(): # 显示
|
|
|
|
if contact is None:
|
|
|
|
i = 20
|
|
|
|
b2 = Button(top, text='添加', width=12, command=lambda: self.add_click(None))
|
|
|
|
show_window = tk.Toplevel(window)
|
|
|
|
self.e7.bind('<Return>', self.add_click)
|
|
|
|
show_window.title('显示员工列表')
|
|
|
|
|
|
|
|
show_window.geometry('320x300')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(show_window, text='姓 名 性 别 年 龄 部 门 手 机 号 码',
|
|
|
|
|
|
|
|
bg='yellow').pack()
|
|
|
|
|
|
|
|
for temp_info in info_list:
|
|
|
|
|
|
|
|
tk.Label(show_window, text=temp_info['姓名']).place(x=0, y=i)
|
|
|
|
|
|
|
|
tk.Label(show_window, text=temp_info['性别']).place(x=70, y=i)
|
|
|
|
|
|
|
|
tk.Label(show_window, text=temp_info['年龄']).place(x=130, y=i)
|
|
|
|
|
|
|
|
tk.Label(show_window, text=temp_info['部门']).place(x=190, y=i)
|
|
|
|
|
|
|
|
tk.Label(show_window, text=temp_info['手机号码']).place(x=260, y=i)
|
|
|
|
|
|
|
|
i += 30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def del_staff_info(): # 删除
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def del_ok_info(): # 确认删除按钮
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dn = del_name.get()
|
|
|
|
|
|
|
|
for i in info_list:
|
|
|
|
|
|
|
|
if dn in i['姓名']:
|
|
|
|
|
|
|
|
del info_list[info_list.index(i)]
|
|
|
|
|
|
|
|
del_window.destroy()
|
|
|
|
|
|
|
|
tk.messagebox.showinfo(title='提示', message='删除成功!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
del_name = tk.StringVar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
del_window = tk.Toplevel(window)
|
|
|
|
|
|
|
|
del_window.title('删除信息')
|
|
|
|
|
|
|
|
del_window.geometry('350x200')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(del_window, text='请输入要删除的员工姓名:').place(x=10, y=10)
|
|
|
|
|
|
|
|
entry_del_name = tk.Entry(del_window, textvariable=del_name)
|
|
|
|
|
|
|
|
entry_del_name.place(x=160, y=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
del_ok_button = tk.Button(del_window, text='确认删除', command=del_ok_info)
|
|
|
|
|
|
|
|
del_ok_button.place(x=150, y=150)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def modify_staff_info(): # 修改
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def modify_ok_info(): # 确认修改按钮
|
|
|
|
|
|
|
|
flag = 0
|
|
|
|
|
|
|
|
on = old_name.get()
|
|
|
|
|
|
|
|
for i in info_list:
|
|
|
|
|
|
|
|
if on in i['姓名']:
|
|
|
|
|
|
|
|
flag = 1
|
|
|
|
|
|
|
|
info_list[info_list.index(i)]['姓名'] = new_name.get()
|
|
|
|
|
|
|
|
info_list[info_list.index(i)]['性别'] = new_sex.get()
|
|
|
|
|
|
|
|
info_list[info_list.index(i)]['年龄'] = new_age.get()
|
|
|
|
|
|
|
|
info_list[info_list.index(i)]['部门'] = new_branch.get()
|
|
|
|
|
|
|
|
info_list[info_list.index(i)]['手机号码'] = new_phone.get()
|
|
|
|
|
|
|
|
modify_window.destroy()
|
|
|
|
|
|
|
|
tk.messagebox.showinfo(title='提示', message='修改成功!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if flag == 0:
|
|
|
|
|
|
|
|
tk.messagebox.showerror(title='警告', message='查无此人!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(info_list) == 0:
|
|
|
|
|
|
|
|
tk.messagebox.showwarning(title='警告', message='员工列表为空!')
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
old_name = tk.StringVar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_name = tk.StringVar()
|
|
|
|
|
|
|
|
new_sex = tk.StringVar()
|
|
|
|
|
|
|
|
new_age = tk.StringVar()
|
|
|
|
|
|
|
|
new_branch = tk.StringVar()
|
|
|
|
|
|
|
|
new_phone = tk.StringVar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modify_window = tk.Toplevel(window)
|
|
|
|
|
|
|
|
modify_window.title('修改信息')
|
|
|
|
|
|
|
|
modify_window.geometry('350x300')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(modify_window, text='请输入要修改的员工姓名:').place(x=10, y=10)
|
|
|
|
|
|
|
|
entry_old_name = tk.Entry(modify_window, textvariable=old_name)
|
|
|
|
|
|
|
|
entry_old_name.place(x=160, y=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(modify_window, text='--------------------请输入要修改后员工信息--------------------').place(x=0,
|
|
|
|
|
|
|
|
y=50)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(modify_window, text='姓 名:').place(x=10, y=80)
|
|
|
|
|
|
|
|
entry_new_name = tk.Entry(modify_window, textvariable=new_name)
|
|
|
|
|
|
|
|
entry_new_name.place(x=60, y=80)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(modify_window, text='性 别:').place(x=10, y=110)
|
|
|
|
|
|
|
|
entry_new_name = tk.Entry(modify_window, textvariable=new_sex)
|
|
|
|
|
|
|
|
entry_new_name.place(x=60, y=110)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(modify_window, text='年 龄:').place(x=10, y=140)
|
|
|
|
|
|
|
|
entry_new_name = tk.Entry(modify_window, textvariable=new_age)
|
|
|
|
|
|
|
|
entry_new_name.place(x=60, y=140)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(modify_window, text='部 门:').place(x=10, y=170)
|
|
|
|
|
|
|
|
entry_new_name = tk.Entry(modify_window, textvariable=new_branch)
|
|
|
|
|
|
|
|
entry_new_name.place(x=60, y=170)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(modify_window, text='部 门:').place(x=10, y=200)
|
|
|
|
|
|
|
|
entry_new_name = tk.Entry(modify_window, textvariable=new_phone)
|
|
|
|
|
|
|
|
entry_new_name.place(x=60, y=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modify_ok_button = tk.Button(modify_window, text='确认修改', command=modify_ok_info)
|
|
|
|
|
|
|
|
modify_ok_button.place(x=140, y=250)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lookup_staff_info(): # 查看
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lookup_ok_info(): # 查找按钮
|
|
|
|
|
|
|
|
flag = 0
|
|
|
|
|
|
|
|
ln = lookup_name.get()
|
|
|
|
|
|
|
|
for i in info_list:
|
|
|
|
|
|
|
|
if ln in i['姓名']:
|
|
|
|
|
|
|
|
flag = 1
|
|
|
|
|
|
|
|
staff_info = tk.Toplevel(lookup_window)
|
|
|
|
|
|
|
|
staff_info.title('员工信息')
|
|
|
|
|
|
|
|
staff_info.geometry('300x300')
|
|
|
|
|
|
|
|
tk.Label(staff_info, text='姓 名:%s' % i['姓名']).place(x=10, y=10)
|
|
|
|
|
|
|
|
tk.Label(staff_info, text='性 别:%s' % i['性别']).place(x=10, y=40)
|
|
|
|
|
|
|
|
tk.Label(staff_info, text='年 龄:%s' % i['年龄']).place(x=10, y=70)
|
|
|
|
|
|
|
|
tk.Label(staff_info, text='部 门:%s' % i['部门']).place(x=10, y=100)
|
|
|
|
|
|
|
|
tk.Label(staff_info, text='手机号码:%s' % i['手机号码']).place(x=10, y=130)
|
|
|
|
|
|
|
|
tk.Button(staff_info, text='关 闭', command=lookup_window.destroy).place(x=200, y=200)
|
|
|
|
|
|
|
|
tk.Button(staff_info, text='继续查找', command=staff_info.destroy).place(x=50, y=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if flag == 0:
|
|
|
|
|
|
|
|
tk.messagebox.showerror(title='提示', message='查无此人!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(info_list) == 0:
|
|
|
|
|
|
|
|
tk.messagebox.showwarning(title='警告', message='员工列表为空!')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
b2 = Button(top, text='编辑', width=12, command=lambda: self.edit_click(None))
|
|
|
|
lookup_name = tk.StringVar()
|
|
|
|
self.e7.bind('<Return>', self.edit_click)
|
|
|
|
lookup_name.set('NONE')
|
|
|
|
b2.pack(side=LEFT, pady=10, padx=20)
|
|
|
|
|
|
|
|
b3 = Button(top, text='取消', width=12, command=lambda: top.destroy())
|
|
|
|
lookup_window = tk.Toplevel(window)
|
|
|
|
b3.pack(side=RIGHT, pady=10, padx=20)
|
|
|
|
lookup_window.title('查看信息')
|
|
|
|
|
|
|
|
lookup_window.geometry('300x200')
|
|
|
|
top.grab_set()
|
|
|
|
|
|
|
|
|
|
|
|
tk.Label(lookup_window, text='员工姓名:').place(x=10, y=10)
|
|
|
|
# 点击编辑职员信息按钮
|
|
|
|
entry_old_name = tk.Entry(lookup_window, textvariable=lookup_name)
|
|
|
|
def edit_click(self, event):
|
|
|
|
entry_old_name.place(x=80, y=10)
|
|
|
|
e1_number = self.e2.get()
|
|
|
|
|
|
|
|
if not e1_number:
|
|
|
|
modify_ok_button = tk.Button(lookup_window, text='查 找', command=lookup_ok_info)
|
|
|
|
messagebox.showinfo("出错了", '名字不能为空!')
|
|
|
|
modify_ok_button.place(x=130, y=150)
|
|
|
|
return
|
|
|
|
|
|
|
|
e2_name = self.e3.get()
|
|
|
|
add_button = tk.Button(window, text='1.添加员工信息', command=add_staff_info)
|
|
|
|
if not e2_name:
|
|
|
|
add_button.pack()
|
|
|
|
messagebox.showinfo("出错了", '性别不能为空!')
|
|
|
|
del_button = tk.Button(window, text='2.删除员工信息', command=del_staff_info)
|
|
|
|
return
|
|
|
|
del_button.pack()
|
|
|
|
e3_name = self.e3.get()
|
|
|
|
modify_button = tk.Button(window, text='3.修改员工信息', command=modify_staff_info)
|
|
|
|
e4_name = self.e4.get()
|
|
|
|
modify_button.pack()
|
|
|
|
e5_name = self.e5.get()
|
|
|
|
lookup_button = tk.Button(window, text='4.查找员工信息', command=lookup_staff_info)
|
|
|
|
e6_name = self.e6.get()
|
|
|
|
lookup_button.pack()
|
|
|
|
e7_name = self.e7.get()
|
|
|
|
show_button = tk.Button(window, text='5.显示员工信息', command=show_staff_info)
|
|
|
|
self.main_window.edit_value(e1_number, e2_name, e3_name, e4_name, e5_name, e6_name, e7_name)
|
|
|
|
show_button.pack()
|
|
|
|
self.top.destroy()
|
|
|
|
show_button = tk.Button(window, text='0.退 出 系 统', command=window.destroy)
|
|
|
|
|
|
|
|
show_button.pack()
|
|
|
|
# 点击添加职员信息按钮
|
|
|
|
|
|
|
|
def add_click(self, event):
|
|
|
|
window.mainloop()
|
|
|
|
e1_name = self.e1.get()
|
|
|
|
|
|
|
|
if not e1_name:
|
|
|
|
|
|
|
|
messagebox.showinfo("出错了", '编号不能为空!')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
e2_name = self.e2.get()
|
|
|
|
|
|
|
|
if not e2_name:
|
|
|
|
|
|
|
|
messagebox.showinfo("出错了", '姓名不能为空!')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
e3_name = self.e3.get()
|
|
|
|
|
|
|
|
e4_name = self.e4.get()
|
|
|
|
|
|
|
|
e5_name = self.e5.get()
|
|
|
|
|
|
|
|
e6_name = self.e6.get()
|
|
|
|
|
|
|
|
e7_name = self.e7.get()
|
|
|
|
|
|
|
|
self.main_window.add_value(e1_name, e2_name, e3_name, e4_name, e5_name, e6_name, e7_name)
|
|
|
|
|
|
|
|
self.top.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 主界面类
|
|
|
|
|
|
|
|
class MainWindow(object):
|
|
|
|
|
|
|
|
# 默认初始化构造
|
|
|
|
|
|
|
|
def __init__(self, root):
|
|
|
|
|
|
|
|
self.contacts = []
|
|
|
|
|
|
|
|
self.root = root
|
|
|
|
|
|
|
|
self.add_btn_widget()
|
|
|
|
|
|
|
|
self.add_search_widget()
|
|
|
|
|
|
|
|
self.add_listbox_widget()
|
|
|
|
|
|
|
|
self.add_statusbar_widget()
|
|
|
|
|
|
|
|
self.read_save_contacts()
|
|
|
|
|
|
|
|
self.sel_item = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加操作按钮
|
|
|
|
|
|
|
|
def add_btn_widget(self):
|
|
|
|
|
|
|
|
frame = Frame(self.root)
|
|
|
|
|
|
|
|
frame.pack(pady=8)
|
|
|
|
|
|
|
|
self.addBtn = Button(frame, text='添加职员信息', width=10, command=lambda: self.popup("添加职员信息"))
|
|
|
|
|
|
|
|
self.addBtn.pack(padx=5, fill=X, side=LEFT)
|
|
|
|
|
|
|
|
self.delAllBtn = Button(frame, text='删除所有信息', width=10, command=self.del_all_contacts)
|
|
|
|
|
|
|
|
self.delAllBtn.pack(padx=5, fill=X, side=LEFT)
|
|
|
|
|
|
|
|
self.saveAllBtn = Button(frame, text='保存所有信息', width=10, command=self.save_all_contacts)
|
|
|
|
|
|
|
|
self.saveAllBtn.pack(padx=5, fill=X, side=LEFT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加搜索框
|
|
|
|
|
|
|
|
def add_search_widget(self):
|
|
|
|
|
|
|
|
frame = Frame(self.root)
|
|
|
|
|
|
|
|
frame.pack(pady=8)
|
|
|
|
|
|
|
|
entry1 = self.input_view = Entry(frame, width=34)
|
|
|
|
|
|
|
|
entry1.insert(0, '输入部分姓名按回车查询')
|
|
|
|
|
|
|
|
entry1.bind("<Button-1>", self.click_input)
|
|
|
|
|
|
|
|
entry1.bind("<FocusOut>", self.focusout_input)
|
|
|
|
|
|
|
|
entry1.bind('<Return>', self.search_contact)
|
|
|
|
|
|
|
|
entry1.bind('<Escape>', self.cancel_search)
|
|
|
|
|
|
|
|
entry1.pack(ipady=3, padx=5, side=LEFT)
|
|
|
|
|
|
|
|
entry1.selection_range(0, len(entry1.get()))
|
|
|
|
|
|
|
|
entry1.focus()
|
|
|
|
|
|
|
|
command4 = self.search_btn = Button(frame, text='清空输入', width=15, command=lambda: self.cancel_search(None))
|
|
|
|
|
|
|
|
command4["state"] = "disabled"
|
|
|
|
|
|
|
|
assert isinstance(LEFT, object)
|
|
|
|
|
|
|
|
command4.pack(padx=5, side=LEFT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 点击输入框清空内容
|
|
|
|
|
|
|
|
def click_input(self, event):
|
|
|
|
|
|
|
|
if self.input_view.get() == '输入部分编号或姓名按回车查询':
|
|
|
|
|
|
|
|
self.input_view.delete(0, END)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 输入框失去焦点时
|
|
|
|
|
|
|
|
def focusout_input(self, event):
|
|
|
|
|
|
|
|
if len(self.input_view.get()) == 0:
|
|
|
|
|
|
|
|
self.input_view.insert(0, '输入部分编号或姓名按回车查询')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加列表及滚动条
|
|
|
|
|
|
|
|
def add_listbox_widget(self):
|
|
|
|
|
|
|
|
frame = Frame(self.root)
|
|
|
|
|
|
|
|
frame.pack(pady=8)
|
|
|
|
|
|
|
|
bolded = font.Font(size=20)
|
|
|
|
|
|
|
|
self.lb = Listbox(frame, font=bolded, height=14, width=25, borderwidth=0)
|
|
|
|
|
|
|
|
scrollbar = Scrollbar(frame, orient=VERTICAL)
|
|
|
|
|
|
|
|
scrollbar.config(command=self.lb.yview)
|
|
|
|
|
|
|
|
scrollbar.pack(side=RIGHT, fill=Y)
|
|
|
|
|
|
|
|
self.lb.config(yscrollcommand=scrollbar.set, activestyle='none')
|
|
|
|
|
|
|
|
scrollbar2 = Scrollbar(frame, orient=HORIZONTAL)
|
|
|
|
|
|
|
|
scrollbar2.config(command=self.lb.xview)
|
|
|
|
|
|
|
|
scrollbar2.pack(side=BOTTOM, fill=X)
|
|
|
|
|
|
|
|
self.lb.config(xscrollcommand=scrollbar2.set, activestyle='none')
|
|
|
|
|
|
|
|
self.lb.pack(fill=BOTH)
|
|
|
|
|
|
|
|
self.lb.bind('<Double-1>', self.dbclick)
|
|
|
|
|
|
|
|
self.lb.bind('<Button-3>', self.rclick_popup)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加界面底部职员人数
|
|
|
|
|
|
|
|
def add_statusbar_widget(self):
|
|
|
|
|
|
|
|
frame = Frame(self.root)
|
|
|
|
|
|
|
|
frame.pack(pady=8, side=LEFT)
|
|
|
|
|
|
|
|
self.label = Label(frame, text='>系统现有 0 位职员<')
|
|
|
|
|
|
|
|
self.label.pack()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 右键菜单
|
|
|
|
|
|
|
|
def rclick_popup(self, event):
|
|
|
|
|
|
|
|
a_menu = Menu(self.root, tearoff=0)
|
|
|
|
|
|
|
|
a_menu.add_command(label='编辑选中的职员信息', command=self.edit_contact)
|
|
|
|
|
|
|
|
a_menu.add_command(label='删除选中的职员信息', command=self.del_contact)
|
|
|
|
|
|
|
|
a_menu.post(event.x_root, event.y_root)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 右键编辑选中的职员信息
|
|
|
|
|
|
|
|
def edit_contact(self):
|
|
|
|
|
|
|
|
selection = self.lb.curselection()
|
|
|
|
|
|
|
|
if len(selection) == 0:
|
|
|
|
|
|
|
|
messagebox.showerror("出错了", '请先左键选中待操作的职员信息!')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
self.sel_item = selection[0]
|
|
|
|
|
|
|
|
self.right_clidk_reset()
|
|
|
|
|
|
|
|
contact = self.contacts[self.sel_item]
|
|
|
|
|
|
|
|
self.popup("编辑职员信息", contact=contact)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 右键删除选中的职员信息
|
|
|
|
|
|
|
|
def del_contact(self):
|
|
|
|
|
|
|
|
selection = self.lb.curselection()
|
|
|
|
|
|
|
|
if len(selection) == 0:
|
|
|
|
|
|
|
|
messagebox.showerror("出错了", '请先左键选中待操作的职员信息!')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
self.right_clidk_reset()
|
|
|
|
|
|
|
|
answer = messagebox.askyesno("提示", "您确定要删除此职员信息吗?")
|
|
|
|
|
|
|
|
if answer:
|
|
|
|
|
|
|
|
self.lb.delete(self.sel_item, self.sel_item)
|
|
|
|
|
|
|
|
self.contacts.pop(self.sel_item)
|
|
|
|
|
|
|
|
self.label.config(text='系统现有 %d 位职员' % len(self.contacts))
|
|
|
|
|
|
|
|
messagebox.showinfo('提示', '职员信息从列表删除成功!\n若需要保存操作结果,请点击“保存所有职员信息”')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 若是搜索后右键,则操作重置列表
|
|
|
|
|
|
|
|
def right_clidk_reset(self, is_dbclick=False):
|
|
|
|
|
|
|
|
b_text = self.search_btn["state"]
|
|
|
|
|
|
|
|
if b_text == "normal":
|
|
|
|
|
|
|
|
ic = -1
|
|
|
|
|
|
|
|
item = self.lb.selection_get()
|
|
|
|
|
|
|
|
if not is_dbclick:
|
|
|
|
|
|
|
|
self.cancel_search(None)
|
|
|
|
|
|
|
|
for ct in self.contacts:
|
|
|
|
|
|
|
|
ic += 1
|
|
|
|
|
|
|
|
if (ct.name in item) and (ct.phone_number in item):
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
self.sel_item = ic
|
|
|
|
|
|
|
|
self.lb.selection_set(ic, ic)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 双击职员信息条目查看详细信息
|
|
|
|
|
|
|
|
def dbclick(self, event):
|
|
|
|
|
|
|
|
selection = self.lb.curselection()
|
|
|
|
|
|
|
|
self.sel_item = selection[0]
|
|
|
|
|
|
|
|
self.right_clidk_reset(is_dbclick=True)
|
|
|
|
|
|
|
|
contact = self.contacts[self.sel_item]
|
|
|
|
|
|
|
|
wp = contact.sex if len(contact.sex) != 0 else '空'
|
|
|
|
|
|
|
|
em = contact.birth if len(contact.birth) != 0 else '空'
|
|
|
|
|
|
|
|
ab = contact.entry_time if len(contact.entry_time) != 0 else '空'
|
|
|
|
|
|
|
|
lh = contact.position if len(contact.position) != 0 else '空'
|
|
|
|
|
|
|
|
mn = contact.salary if len(contact.salary) != 0 else '空'
|
|
|
|
|
|
|
|
msg = '编号:%s\n姓名:%s\n性别:%s\n出生日期:%s\n入职时间:%s\n职位:%s\n工资:%s\n' % (
|
|
|
|
|
|
|
|
contact.number, contact.name, wp, em, ab, lh, mn)
|
|
|
|
|
|
|
|
messagebox.showinfo("详细信息", msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加、编辑员工信息弹窗
|
|
|
|
|
|
|
|
def popup(self, title, contact=None):
|
|
|
|
|
|
|
|
self.cancel_search(None)
|
|
|
|
|
|
|
|
self.w = PopupWindow(self.root, self, title, contact)
|
|
|
|
|
|
|
|
self.addBtn["state"] = "disabled"
|
|
|
|
|
|
|
|
self.root.wait_window(self.w.top)
|
|
|
|
|
|
|
|
self.addBtn["state"] = "normal"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 删除所有员工信息
|
|
|
|
|
|
|
|
def del_all_contacts(self):
|
|
|
|
|
|
|
|
self.cancel_search(None)
|
|
|
|
|
|
|
|
answer = messagebox.askyesno("提示", "您确定要删除所有信息吗?")
|
|
|
|
|
|
|
|
if answer:
|
|
|
|
|
|
|
|
self.contacts.clear()
|
|
|
|
|
|
|
|
self.lb.delete(0, END)
|
|
|
|
|
|
|
|
remove("contacts.csv")
|
|
|
|
|
|
|
|
self.label.config(text='系统现有 %d 位职员' % len(self.contacts))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 保存职员信息到文件
|
|
|
|
|
|
|
|
def save_all_contacts(self):
|
|
|
|
|
|
|
|
self.cancel_search(None)
|
|
|
|
|
|
|
|
f = open("contacts.csv", "w", encoding='utf-8')
|
|
|
|
|
|
|
|
for contact in self.contacts:
|
|
|
|
|
|
|
|
str = '{},{},{},{}\n'.format(contact.number, contact.name, contact.sex, contact.birth, contact.entry_time,
|
|
|
|
|
|
|
|
contact.position, contact.salary)
|
|
|
|
|
|
|
|
f.write(str)
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
messagebox.showinfo('提示', '保存 %d 位职员信息到文件成功!' % len(self.contacts))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 读取保存在文件的职员信息
|
|
|
|
|
|
|
|
def read_save_contacts(self):
|
|
|
|
|
|
|
|
if not path.exists('contacts.csv'):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
f = open("contacts.csv", "r", encoding='utf-8')
|
|
|
|
|
|
|
|
for line in f:
|
|
|
|
|
|
|
|
array = line.strip().split(',')
|
|
|
|
|
|
|
|
contact = Contact(array[0], array[1], array[2], array[3], array[4], array[5], array[6])
|
|
|
|
|
|
|
|
self.contacts.append(contact)
|
|
|
|
|
|
|
|
self.lb.insert(END, '编号:%s 姓名:%s性别:%s出生日期:%s入职时间:%s职位:%s工资:%s' % (
|
|
|
|
|
|
|
|
contact.number, contact.name, contact.sex, contact.birth, contact.entry_time, contact.position,
|
|
|
|
|
|
|
|
contact.salary))
|
|
|
|
|
|
|
|
self.label.config(text='系统现有 %d 位职员' % len(self.contacts))
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 添加职员信息回调
|
|
|
|
|
|
|
|
def add_value(self, number, name, sex, birth, entry_time, position, salary):
|
|
|
|
|
|
|
|
contact = Contact(number, name, sex, birth, entry_time, position, salary)
|
|
|
|
|
|
|
|
self.contacts.append(contact)
|
|
|
|
|
|
|
|
self.lb.insert(END, '编号:%s 姓名:%s性别:%s出生日期:%s入职时间:%s职位:%s工资:%s' % (
|
|
|
|
|
|
|
|
contact.number, contact.name, contact.sex, contact.birth, contact.entry_time, contact.position, contact.salary))
|
|
|
|
|
|
|
|
self.label.config(text='系统现有 %d 位职员' % len(self.contacts))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 编辑职员信息回调
|
|
|
|
|
|
|
|
def edit_value(self, number, name, sex, birth, entry_time, position, salary):
|
|
|
|
|
|
|
|
contact = self.contacts[self.sel_item]
|
|
|
|
|
|
|
|
contact.number = number
|
|
|
|
|
|
|
|
contact.name = name
|
|
|
|
|
|
|
|
contact.sex = sex
|
|
|
|
|
|
|
|
contact.birth = birth
|
|
|
|
|
|
|
|
contact.entry_time = entry_time
|
|
|
|
|
|
|
|
contact.position = position
|
|
|
|
|
|
|
|
contact.salary = salary
|
|
|
|
|
|
|
|
self.lb.delete(0, END)
|
|
|
|
|
|
|
|
for contact in self.contacts:
|
|
|
|
|
|
|
|
self.lb.insert(END, '编号:%s 姓名:%s性别:%s出生日期:%s入职时间:%s职位:%s工资:%s' % (
|
|
|
|
|
|
|
|
contact.number, contact.name, contact.sex, contact.birth, contact.entry_time, contact.position,
|
|
|
|
|
|
|
|
contact.salary))
|
|
|
|
|
|
|
|
self.label.config(text='系统现有 %d 位职员' % len(self.contacts))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 搜索职员信息方法
|
|
|
|
|
|
|
|
def search_contact(self, event):
|
|
|
|
|
|
|
|
self.search_btn["state"] = "normal"
|
|
|
|
|
|
|
|
self.lb.delete(0, END)
|
|
|
|
|
|
|
|
key = self.input_view.get().strip()
|
|
|
|
|
|
|
|
ci = 0
|
|
|
|
|
|
|
|
for contact in self.contacts:
|
|
|
|
|
|
|
|
if (key in contact.number) or (key in contact.name):
|
|
|
|
|
|
|
|
self.lb.insert(END, '编号:%s 姓名:%s性别:%s出生日期:%s入职时间:%s职位:%s工资:%s' % (
|
|
|
|
|
|
|
|
contact.number, contact.name, contact.sex, contact.birth, contact.entry_time, contact.position,
|
|
|
|
|
|
|
|
contact.salary))
|
|
|
|
|
|
|
|
ci += 1
|
|
|
|
|
|
|
|
self.label.config(text='查询到 %d 位职员' % ci)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 取消搜索
|
|
|
|
|
|
|
|
def cancel_search(self, event):
|
|
|
|
|
|
|
|
b_state = self.search_btn["state"]
|
|
|
|
|
|
|
|
if b_state == "normal":
|
|
|
|
|
|
|
|
self.search_btn["state"] = "disabled"
|
|
|
|
|
|
|
|
self.lb.delete(0, END)
|
|
|
|
|
|
|
|
self.input_view.delete(0, END)
|
|
|
|
|
|
|
|
self.input_view.insert(0, '输入部分编号或姓名按回车查询')
|
|
|
|
|
|
|
|
for contact in self.contacts:
|
|
|
|
|
|
|
|
self.lb.insert(END, '编号:%s 姓名:%s性别:%s出生日期:%s入职时间:%s职位:%s工资:%s' % (
|
|
|
|
|
|
|
|
contact.number, contact.name, contact.sex, contact.birth, contact.entry_time, contact.position,
|
|
|
|
|
|
|
|
contact.salary))
|
|
|
|
|
|
|
|
self.label.config(text='系统现有 %d 位职员' % len(self.contacts))
|
|
|
|
|
|
|
|
self.input_view.selection_range(0, len(self.input_view.get()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 职员类对象
|
|
|
|
|
|
|
|
class Contact:
|
|
|
|
|
|
|
|
def __init__(self, number: object, name: object, sex: object, birth: object, entry_time: object, position: object,
|
|
|
|
|
|
|
|
salary: object) -> object:
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
:rtype: object
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.number = number
|
|
|
|
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
self.sex = sex
|
|
|
|
|
|
|
|
self.birth = birth
|
|
|
|
|
|
|
|
self.entry_time = entry_time
|
|
|
|
|
|
|
|
self.position = position
|
|
|
|
|
|
|
|
self.salary = salary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 程序启动入口
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
root = Tk()
|
|
|
|
|
|
|
|
root.wm_resizable(False, False)
|
|
|
|
|
|
|
|
root.title('人事管理系统')
|
|
|
|
|
|
|
|
w = 380
|
|
|
|
|
|
|
|
h = 560
|
|
|
|
|
|
|
|
ws = root.winfo_screenwidth()
|
|
|
|
|
|
|
|
hs = root.winfo_screenheight()
|
|
|
|
|
|
|
|
root.geometry('%dx%d+%d+%d' % (w, h, (ws - w) / 2, (hs - h) / 2))
|
|
|
|
|
|
|
|
m = MainWindow(root)
|
|
|
|
|
|
|
|
root.mainloop()
|
|
|
|
|
|
|
|
# Press the green button in the gutter to run the script.
|
|
|
|
# Press the green button in the gutter to run the script.
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print_hi('PyCharm')
|
|
|
|
print_hi('PyCharm')
|
|
|
|