|
|
import os
|
|
|
import tkinter
|
|
|
|
|
|
import psutil,time,threading
|
|
|
import ttkbootstrap
|
|
|
from tkinter import *
|
|
|
from tkinter import ttk, messagebox
|
|
|
import zipfile
|
|
|
|
|
|
import tkinter as tk
|
|
|
import _sqlite3
|
|
|
|
|
|
# 数据库
|
|
|
conn = _sqlite3.connect("data.db")
|
|
|
c = conn.cursor()
|
|
|
# c.execute("create table score(itemName char(20),importPrice char(20),"
|
|
|
# "sellPrice char(20),deductPrice char(20))")
|
|
|
def Serchone(sellPrice):
|
|
|
c.execute("select itemName,deductPrice from score where score.sellPrice = '%s'" % sellPrice)
|
|
|
return c.fetchall()
|
|
|
def Serchone2():
|
|
|
c.execute("select itemName,deductPrice from score order by deductPrice desc")
|
|
|
return c.fetchall()
|
|
|
#根据id查询教师个人信息sql语句
|
|
|
def SerchMy(name):
|
|
|
c.execute("select * from students where students.name = '%s'" % name)
|
|
|
return c.fetchall()
|
|
|
#修改密码sql语句
|
|
|
def UpdatePassWord(id, name):
|
|
|
c.execute('update students set id = (?) where name = (?)',
|
|
|
(id, name))
|
|
|
# 提交事务
|
|
|
conn.commit()
|
|
|
|
|
|
#主窗体
|
|
|
class InputFrame(Frame): # 继承Frame类
|
|
|
def __init__(self, master=None):
|
|
|
Frame.__init__(self, master)
|
|
|
self.root = master # 定义内部变量root
|
|
|
self.createPage()
|
|
|
|
|
|
def createPage(self):
|
|
|
Label(self, text='欢迎登录信息管理系统!!!', font=('华文行楷', 20), fg='purple').pack()
|
|
|
# #实现测网速
|
|
|
# def _():
|
|
|
# meter = ttkbootstrap.Meter(
|
|
|
# metersize=180,
|
|
|
# padding=50,
|
|
|
# amountused=0,
|
|
|
# metertype="semi",
|
|
|
# subtext="当前网速(kB/s)",
|
|
|
# subtextstyle="warning",
|
|
|
# interactive=False,
|
|
|
# bootstyle='primary',
|
|
|
# )
|
|
|
# meter.pack(side=ttkbootstrap.LEFT, padx=5)
|
|
|
# while True:
|
|
|
# meter.configure(amountused=round(getNet(), 2))
|
|
|
# def getNet():
|
|
|
# recv_before = psutil.net_io_counters().bytes_recv
|
|
|
# time.sleep(1)
|
|
|
# recv_now = psutil.net_io_counters().bytes_recv
|
|
|
# recv = (recv_now - recv_before) / 1024
|
|
|
# return recv
|
|
|
# t = threading.Thread(target=_)
|
|
|
# t.setDaemon(True)
|
|
|
# t.start()
|
|
|
|
|
|
#我的信息
|
|
|
class MyFrame(Frame):
|
|
|
def __init__(self, name, master=None):
|
|
|
Frame.__init__(self, master)
|
|
|
self.root = master # 定义内部变量root
|
|
|
self.name = name
|
|
|
self.createPage()
|
|
|
|
|
|
def createPage(self):
|
|
|
Button(self, text='个人信息', command=self.My_Page).pack()
|
|
|
def My_Page(self):
|
|
|
li = SerchMy(self.name)
|
|
|
pth = li[0]
|
|
|
print(pth)
|
|
|
Label(self, text='工号: ').pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='%s' % pth[0]).pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='姓名: ').pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='%s' % pth[1]).pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='性别: ').pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='%s' % pth[2]).pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='专业: ').pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='%s' % pth[3]).pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='职称: ').pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='%s' % pth[4]).pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='入职年月: ').pack(side=LEFT,ipady=10)
|
|
|
Label(self, text='%s' % pth[5]).pack(side=LEFT,ipady=10)
|
|
|
|
|
|
|
|
|
#修改密码
|
|
|
class UpdatepwdFrame(Frame):
|
|
|
def __init__(self, name, master=None):
|
|
|
Frame.__init__(self, master)
|
|
|
self.root = master # 定义内部变量root
|
|
|
self.name = name
|
|
|
self.id = StringVar()
|
|
|
self.createPage()
|
|
|
|
|
|
def createPage(self):
|
|
|
Button(self, text='修改密码', command=self.My_Page).grid()
|
|
|
|
|
|
|
|
|
def My_Page(self):
|
|
|
li = SerchMy(self.name)
|
|
|
pth = li[0]
|
|
|
print(pth)
|
|
|
self.id = tkinter.StringVar()
|
|
|
self.ids = tkinter.StringVar()
|
|
|
Label(self).grid(row=0, stick=W, pady=10)
|
|
|
Label(self, text='请输入新密码: ').grid(row=1, stick=W, pady=10)
|
|
|
Entry(self, textvariable=self.id).grid(row=1, column=1, stick=E)
|
|
|
Label(self, text='确认密码: ').grid(row=2, stick=W, pady=10)
|
|
|
Entry(self, textvariable=self.ids).grid(row=2, column=1, stick=E)
|
|
|
Button(self, text='确认修改', width=8, height=2, command=self.UpdateDate).grid(row=3, column=1, stick=E)
|
|
|
self.id.set('')
|
|
|
self.ids.set('')
|
|
|
|
|
|
def UpdateDate(self):
|
|
|
UpdatePassWord(self.id.get(),self.name)
|
|
|
tkinter.messagebox.showerror("成功", "修改成功")
|
|
|
|
|
|
#查看成绩类
|
|
|
class QueryFrame(Frame): # 继承Frame类
|
|
|
def __init__(self, master=None):
|
|
|
Frame.__init__(self, master)
|
|
|
self.root = master # 定义内部变量root
|
|
|
self.itemName = StringVar()
|
|
|
self.sellPrice = StringVar()
|
|
|
self.createPage()
|
|
|
|
|
|
def createPage(self):
|
|
|
Label(self, text='我的成绩', font=('华文行楷', 20), fg='purple').pack()
|
|
|
columns = ("itemName", "deductPrice")
|
|
|
columns_values = ("课程名称", "成绩")
|
|
|
self.tree_view = ttk.Treeview(self, show='headings', columns=columns)
|
|
|
self.tree_view.column('itemName', width=80, anchor='center')
|
|
|
self.tree_view.column('deductPrice', width=80, anchor='center')
|
|
|
self.tree_view.heading('itemName', text='课程名称')
|
|
|
self.tree_view.heading('deductPrice', text='成绩')
|
|
|
self.tree_view.pack(fill=tk.BOTH, expand=True)
|
|
|
scores = Serchone2()
|
|
|
print(scores)
|
|
|
index = 0
|
|
|
for s in scores:
|
|
|
print(s)
|
|
|
self.tree_view.insert('', index + 1, values=(
|
|
|
s[0], s[1],
|
|
|
))
|
|
|
#意见反馈类
|
|
|
class CountFrame(Frame): # 继承Frame类
|
|
|
def __init__(self, master=None):
|
|
|
Frame.__init__(self, master)
|
|
|
self.root = master # 定义内部变量root
|
|
|
self.createPage()
|
|
|
|
|
|
def createPage(self):
|
|
|
Label(self, text='请说出你的想法', font=('华文行楷', 20), fg='purple').pack()
|
|
|
text = tk.Text(self, width=100, height=20)
|
|
|
text.pack()
|
|
|
text.insert("insert", "")
|
|
|
text.insert('end', '\n')
|
|
|
mytxtfile = "mytxtfile.txt"
|
|
|
# 读取TXT文件,显示在tkinter的Text
|
|
|
def in_f_txt():
|
|
|
if os.path.exists(mytxtfile):
|
|
|
a = open(mytxtfile, 'r', encoding='utf-8')
|
|
|
for id_names in a:
|
|
|
text.insert('insert', id_names)
|
|
|
a.close()
|
|
|
|
|
|
text.insert('end', '\n')
|
|
|
# 输入文本框
|
|
|
input_txt = tk.Entry(self, width=20)
|
|
|
input_txt.pack()
|
|
|
|
|
|
def add():
|
|
|
# 通过get()函数获得Text(input_txt)的输入内容
|
|
|
var_id = input_txt.get()
|
|
|
h = open(mytxtfile, 'a+', encoding='utf-8')
|
|
|
h.write(var_id + '\n') # 添加到文件夹中的txt
|
|
|
h.close()
|
|
|
|
|
|
b2 = tk.Button(text, text="提交意见", command=add)
|
|
|
text.window_create("insert", window=b2)
|
|
|
text.insert('end', '\n')
|
|
|
|
|
|
#提交作业
|
|
|
class SubmitFrame(Frame): # 继承Frame类
|
|
|
def __init__(self, master=None):
|
|
|
Frame.__init__(self, master)
|
|
|
self.root = master # 定义内部变量root
|
|
|
self.createPage()
|
|
|
|
|
|
def createPage(self):
|
|
|
Button(self, text='提交作业', font=('华文行楷', 20), command=self.show_submit_frame).pack(anchor='center', pady=5)
|
|
|
#提交作业
|
|
|
def show_submit_frame(self):
|
|
|
window = tk.Tk()
|
|
|
window.title("提交作业")
|
|
|
window.geometry("800x600") # 窗口设置
|
|
|
window.resizable(0, 0) # 固定窗口大小
|
|
|
|
|
|
var = tk.StringVar() # 输入框内容
|
|
|
self.num = 1 # 已生成的作业数量+1
|
|
|
source = str() # 单个源代码的内容
|
|
|
self.path = str() # 打包相对路径
|
|
|
# __Labels
|
|
|
head = tk.Label(window, text=" 请将第{num}题源代码复制到框中:".format(num=self.num),
|
|
|
font=('Arial', 15), width=20, height=1)
|
|
|
# 这里的长宽以字符为单位
|
|
|
head.place(x=40, y=100, anchor='nw')
|
|
|
|
|
|
name = tk.Label(window, text="请输入姓名:", font=('Arial', 15), )
|
|
|
name.place(x=3, y=5, anchor='nw')
|
|
|
|
|
|
xuehao = tk.Label(window, text="请输入学号:", font=('Arial', 15), )
|
|
|
xuehao.place(x=3, y=35, anchor='nw')
|
|
|
|
|
|
ok_txt = tk.Label(window, text="点击确定即可\n以框中内容\n生成一个.py文件:", font=('Arial', 15))
|
|
|
ok_txt.place(x=600, y=20, anchor='nw')
|
|
|
|
|
|
# __Entrys
|
|
|
name_en = tk.Entry(window)
|
|
|
name_en.place(x=145, y=8, anchor='nw')
|
|
|
|
|
|
xuehao_en = tk.Entry(window)
|
|
|
xuehao_en.place(x=145, y=38, anchor='nw')
|
|
|
|
|
|
# __Buttons
|
|
|
def make_zip(floder, backupfilename): # floder:要打包的文件夹;backupfilename:指定文件名
|
|
|
backupfilename = backupfilename + '.zip'
|
|
|
f = zipfile.ZipFile(backupfilename, 'w') # c创建一个zip对象
|
|
|
|
|
|
for floderName, subFolders, fileNames in os.walk(floder):
|
|
|
f.write(floderName)
|
|
|
for subFolder in subFolders:
|
|
|
f.write(os.path.join(floderName, subFolder))
|
|
|
for fileName in fileNames:
|
|
|
f.write(os.path.join(floderName, fileName))
|
|
|
f.close()
|
|
|
|
|
|
def ok_hit(): ##确认 键的功能
|
|
|
# global path
|
|
|
self.path = "./{xuehao}_{name}".format(xuehao=xuehao_en.get(), name=name_en.get())
|
|
|
folder = os.path.exists(self.path)
|
|
|
if not folder:
|
|
|
os.makedirs(self.path)
|
|
|
source = content.get("0.0", "end")
|
|
|
|
|
|
with open(self.path + '/' + "第{num}题.py".format(num=self.num), 'w') as f:
|
|
|
f.write(source)
|
|
|
self.num += 1
|
|
|
head.config(text="请将第{num}题源代码复制到框中:".format(num=self.num))
|
|
|
content.delete("0.0", 'end')
|
|
|
pass
|
|
|
|
|
|
def zip_them_hit(): ##打包键功能
|
|
|
make_zip(self.path, "{xuehao}_{name}".format
|
|
|
(xuehao=xuehao_en.get(), name=name_en.get()))
|
|
|
messagebox.showinfo(message="你的 {num} 个.py语言源代码\n已经打包入zip压缩包中\n在当前目录即可找到".format(num=self.num-1), title="Packing has been complished!")
|
|
|
os.system("explorer " + os.getcwd())
|
|
|
window.destroy() ##结束程序
|
|
|
pass
|
|
|
#创建Buttons
|
|
|
ok = tk.Button(window, text="确 定", command=ok_hit, width=10, height=2, font=40)
|
|
|
ok.place(x=650, y=120, anchor='nw')
|
|
|
|
|
|
zip_them = tk.Button(window, text="打包成zip", command=zip_them_hit, width=10,height=2, font=40)
|
|
|
zip_them.place(x=650, y=250, anchor='nw')
|
|
|
# __Texts
|
|
|
content = tk.Text(window, width=65, height=30)
|
|
|
content.place(x=20, y=130, anchor='nw')
|
|
|
window.mainloop()
|