You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import PySimpleGUI as sg
import openpyxl
import xlrd
import random
def TakeRoll():
book = xlrd.open_workbook('sample.xlsx')
sheet = book.sheet_by_index(0)
book = openpyxl.load_workbook(filename='sample.xlsx')
ins_sheet = book.active
if sheet.ncols == 2:
ins_sheet['C1'] = 'Scredit'
idx = random.randint(2, sheet.nrows)
stu = str(ins_sheet.cell(row=idx, column=1).value) + ins_sheet.cell(row=idx, column=2).value
i = 2
while i <= sheet.nrows:
ins_sheet.cell(row=i, column=3).value = 0
i += 1
book.save(filename='sample.xlsx')
return stu, idx
else: #学生表中含有已创建的SCredit列
max = 0
credit = ins_sheet['C'] #将SCredit列存入redit数组
i = 1
while i <= sheet.nrows-1:
credit[i].value *= 2 #将所有积分值整数化所有非整数积分值小数部分均为0.5
i += 1
i = 1
while i <= sheet.nrows-1:
if credit[i].value > max:
max = credit[i].value
i += 1
max += 1 #求出最大积分值并加1
slct = []
i = 1
while i <= sheet.nrows-1:
credit[i].value = max - credit[i].value #倒转积分值将最大的积分值置为1其余积分依次增大
r = 1
while r <= int(credit[i].value):
slct.append(i)
r += 1 #第i个学生倒转后的积分值即为slct数组中对应第i个学生的元素个数和该生被选中的概率呈负相关
i += 1
idx = random.randint(0, len(slct)-1)
stu = str(ins_sheet.cell(row=slct[idx]+1, column=1).value) + ins_sheet.cell(row=slct[idx]+1, column=2).value
return stu, slct[idx]+1
def CreditUpdate(stu, isInc, point):
book = openpyxl.load_workbook(filename='sample.xlsx')
sheet = book.active
if isInc == True:
sheet.cell(row=stu, column=3).value += point
else:
sheet.cell(row=stu, column=3).value -= point
book.save(filename='sample.xlsx')
layoutA = [
[sg.Text('被点到的同学:'), sg.Text('', key = 'roll')],
[sg.Button('点名')]
]
layoutB1 = [
[sg.Button(''), sg.Button('')],
]
layoutB2 = [
[sg.Button(''), sg.Button('')],
]
layoutB3 = [
[sg.Button(''), sg.Button('')],
]
layoutC = [
[sg.Button('回答问题'), sg.Button('请ta坐下')],
]
List = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
layoutD = [
[sg.Drop(List,
default_value = None,
size = (30, 6),
enable_events = True,
key = 'point'
)],
[sg.Button('确认')]
]
window = sg.Window('点名', layoutA)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
if event == '点名':
ret, rownum = TakeRoll()
window['roll'].update(value=ret)
window = sg.Window('该同学是否到位?', layoutB1)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, ''):
break
if event == '':
CreditUpdate(rownum, True, 1.0)
window = sg.Window('接下来...', layoutC)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, '请ta坐下'):
break
if event == '回答问题':
window = sg.Window('该同学能否复述问题?', layoutB2)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
if event == '':
CreditUpdate(rownum, True, 0.5)
window = sg.Window('该同学答对问题了吗?', layoutB3)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, ''):
break
if event == '':
window = sg.Window('给ta打分', layoutD)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
if event == '确认':
CreditUpdate(rownum, True, values['point'])
break
break
break
if event == '':
CreditUpdate(rownum, False, 1.0)
break
break
break
break
window.close()