附件就不上传了,直接放源代码。有特殊需求的可以随意编辑。最后用pyinstaller封装就可以。
[i]
教师服务端:
import tkinter as tk
from flask import Flask, request
import pandas as pd
from threading import Thread
app = Flask(__name__)
@app.route('/index', methods=['GET', 'POST'])
def index():
name = request.form.get('name')
source = request.form.get('source')
ip = request.form.get('ip')
ls.append([name, source, ip])
return '上传成功'
def open_flask():
app.run(
host='0.0.0.0'
)
def start_server():
server_thread = Thread(target=open_flask)
server_thread.start()
def save_data():
df = pd.DataFrame(ls, columns=['姓名', '成绩', 'IP地址'])
df.to_csv('成绩汇总.csv', index=False)
ls = []
root = tk.Tk()
# 窗口标题
root.title('模拟成绩接收器-教师端')
# 窗口大小
root.geometry('300x200')
butn1 = tk.Button(
root,
text='启动服务', # 按键上的文字
width=10, height=2,
command=start_server # 按键控制的执行命令
)
butn1.pack()
butn2 = tk.Button(
root,
text='保存数据', # 按键上的文字
width=10, height=2,
command=save_data # 按键控制的执行命令
)
butn2.pack()
root.mainloop()
学生请求端:
import time
import socket
import requests
import re
import tkinter as tk
def get_data():
ip = socket.gethostbyname(socket.gethostname())
name = name_l.get()
uip = uip_l.get()
level = level_l.get()
try:
path = ''
if level == '1':
path = 'WP'
elif level == '2':
path = 'TW'
# 这一步非常重要:定义你的机房学生机器模拟软件的安装路径!
with open(f'C:\\Users\\admin\\Desktop\\NCRE\\{path}\\UserData\\UserPractice\\ExamRecord.xml', 'r', encoding='utf-8') as f:
fr = f.read()
com = re.compile('(.*?)')
source = com.findall(fr)[-1]
print(name, uip, level, source, ip)
dic = {
'name': name,
'source': source,
'ip': ip
}
URL = f'http://{uip}:5000/index'
response = requests.post(URL, dic)
except:
pass
root = tk.Tk()
# 窗口标题
root.title('模拟成绩发送器-学生端')
# 窗口大小
root.geometry('300x200')
# 文字变量存储器
var = tk.StringVar()
tk.Label(root, text='请输入姓名:').pack()
name_l = tk.Entry(root)
name_l.pack()
tk.Label(root, text='请输入教师机IP:').pack()
uip_l = tk.Entry(root)
uip_l.pack()
tk.Label(root, text='请输入等级(1/2):').pack()
level_l = tk.Entry(root)
level_l.pack()
butn = tk.Button(
root,
text='发送分数', # 按键上的文字
width=10, height=2,
command=get_data # 按键控制的执行命令
)
butn.pack()
root.mainloop()