ADD file via upload

main
p49flchze 1 month ago
parent d5fec247af
commit 9a74436ed5

@ -0,0 +1,144 @@
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')
else:
max = 0
credit = ins_sheet['C']
i = 1
while i <= sheet.nrows-1:
credit[i].value *= 2
i += 1
i = 1
while i <= sheet.nrows-1:
if credit[i].value > max:
max = credit[i].value
i += 1
'''
while i<=sheet.nrows:
if ins_sheet.cell(row=i, column=3).value > max:
max = ins_sheet.cell(row=i, column=3).value
i += 1
'''
max += 1
slct = []
i = 1
while i <= sheet.nrows-1:
credit[i].value = max - credit[i].value
r = 1
while r <= int(credit[i].value):
slct.append(i)
r += 1
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()
Loading…
Cancel
Save