From f900f0016b72063bf7bc0bd381a715fa30565134 Mon Sep 17 00:00:00 2001 From: HCha Date: Mon, 7 Nov 2022 18:02:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=86=8D=E4=B8=8A=E4=BC=A0=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .history/README_20221107174914.md | 47 ------- .history/README_20221107175110.md | 47 ------- .history/点名器_20221107012031.pyw | 189 ---------------------------- .history/点名器_20221107175501.pyw | 189 ---------------------------- .history/点名器_20221107175513.pyw | 189 ---------------------------- .history/点名器_20221107175603.pyw | 192 ----------------------------- .history/点名器_20221107175606.pyw | 191 ---------------------------- .history/点名器_20221107175614.pyw | 191 ---------------------------- .history/点名器_20221107175730.pyw | 190 ---------------------------- .history/点名器_20221107175743.pyw | 192 ----------------------------- .history/点名器_20221107175744.pyw | 192 ----------------------------- .history/点名器_20221107175745.pyw | 192 ----------------------------- 12 files changed, 2001 deletions(-) delete mode 100644 .history/README_20221107174914.md delete mode 100644 .history/README_20221107175110.md delete mode 100644 .history/点名器_20221107012031.pyw delete mode 100644 .history/点名器_20221107175501.pyw delete mode 100644 .history/点名器_20221107175513.pyw delete mode 100644 .history/点名器_20221107175603.pyw delete mode 100644 .history/点名器_20221107175606.pyw delete mode 100644 .history/点名器_20221107175614.pyw delete mode 100644 .history/点名器_20221107175730.pyw delete mode 100644 .history/点名器_20221107175743.pyw delete mode 100644 .history/点名器_20221107175744.pyw delete mode 100644 .history/点名器_20221107175745.pyw diff --git a/.history/README_20221107174914.md b/.history/README_20221107174914.md deleted file mode 100644 index a6f31fb..0000000 --- a/.history/README_20221107174914.md +++ /dev/null @@ -1,47 +0,0 @@ -# ---一个点名器的python实现--- -## 读取相同目录下的names.xls数据库文件 -## 程序启动后如果检测到数据库文件会自动加上隐藏属性 -## names.xls必须满足以下条件: -### 1. 至少两行和不多于也不少于四列 -### 2. 第一行的四个单元格分别是 |序号|班级|学科|姓名 -### 3. 第二行以下分别按照第一行的要求填写 - -#### P.S. 第一行的四个单元格会被程序自动忽略,这四个名称只是为了让人方便阅读 - -### 软件会自动读取数据库中所有可用的班级名称,并将列举在软件右侧的选择框内。 - -![image](https://user-images.githubusercontent.com/10991308/200275407-fc43e648-275f-455e-a7c7-2fec00e074e2.png) - -### 左击选择框可以选择按照班级的筛选,可以多选,如果不选,则默认不进行筛选。 - -![image](https://user-images.githubusercontent.com/10991308/200275805-0d64667f-238e-42bb-a332-3be33fd0b5ec.png) - -### 点击`立即摇人!`可以在所有满足筛选条件的人员中随机挑选一位,并将其姓名,班级号和学科种类显示在界面上。 - -![image](https://user-images.githubusercontent.com/10991308/200276213-2eabcb19-7bde-4eca-985e-e0ddf939b484.png) - -### 点击`应用班级选用`可以提前应用筛选条件,但不会进行挑选。 - -~~但是点击摇人的时候本来就会重新应用当前选好的筛选条件,所以这个按钮其实就是做来好看的。~~ - -### 为了防止被搞心态,不会出现连续抽到两个一样的人的情况。~~因为懒得写动画所以如果连续抽到两个一样的人就几乎看不出来了~~ - -## 隐藏功能:使用config.data文件对指定编号的人员进行指定概率编辑 - -~~究竟是什么居心的人才想让我开发这么一个鬼功能~~ - -![image](https://user-images.githubusercontent.com/10991308/200277374-0ff24e74-53d6-4d22-b513-bccc9f1af241.png) -![image](https://user-images.githubusercontent.com/10991308/200277421-a81b11a2-eec2-4373-957a-37dc134ef0b8.png) - -### 在相同目录下编辑一个config.data文件 -### 如果程序没有检测到文件,什么都不会发生 -### 如果检测到了,自动加隐藏属性并读取文件 -### config.data需要符合以下语法: -#### 1. 由N行组成 -#### 2. 每一行对应一位需要更改概率的序号 -#### 3. 每一行的内容为 `X,+/-/0` 即需要编辑的序号加上一个英文字符逗号加上英文字符+或者-或者数字0 -#### 4. 请再看一遍`3.`并确保你记住了每一个词 -#### 5. 如果输入了`+`,那么该序号被抽到的概率增加(前提是满足由班级选择器控制的筛选条件)。具体增加方法为每次抽人都有5% * (被标记为‘+’的人的人数)的概率只在被标记为‘+’的人中抽取,这个总概率的上限为30%。 -#### 6. 如果输入了`-`,那么该序号被抽到的概率减少。具体减少方法是每次抽人都有8% * (被标记为‘-’的人的人数)直接排除掉这些被标记的人。这个概率的上限是40%。 -#### 7. 如果输入了`0`,那么该序号便会被拒绝录入。即数据库中虽然存在该编号,但是程序不会将其视为可被抽取的对象。 -#### 8. 如欲更改配置,仅需在保存了更改后的配置文件后重启点名器程序即可。 diff --git a/.history/README_20221107175110.md b/.history/README_20221107175110.md deleted file mode 100644 index 6b9bcbb..0000000 --- a/.history/README_20221107175110.md +++ /dev/null @@ -1,47 +0,0 @@ -# ---一个点名器的python实现--- -## 读取相同目录下的names.xls数据库文件 -## 程序启动后如果检测到数据库文件会自动加上隐藏属性 -## names.xls必须满足以下条件: -### 1. 至少两行和不多于也不少于四列 -### 2. 第一行的四个单元格分别是 |序号|班级|学科|姓名 -### 3. 第二行以下分别按照第一行的要求填写 - -#### P.S. 第一行的四个单元格会被程序自动忽略,这四个名称只是为了让人方便阅读 - -### 软件会自动读取数据库中所有可用的班级名称,并将列举在软件右侧的选择框内。 - -![image](https://user-images.githubusercontent.com/10991308/200275407-fc43e648-275f-455e-a7c7-2fec00e074e2.png) - -### 左击选择框可以选择按照班级的筛选,可以多选,如果不选,则默认不进行筛选。 - -![image](https://user-images.githubusercontent.com/10991308/200275805-0d64667f-238e-42bb-a332-3be33fd0b5ec.png) - -### 点击`立即摇人!`可以在所有满足筛选条件的人员中随机挑选一位,并将其姓名,班级号和学科种类显示在界面上。 - -![image](https://user-images.githubusercontent.com/10991308/200276213-2eabcb19-7bde-4eca-985e-e0ddf939b484.png) - -### 点击`应用班级选用`可以提前应用筛选条件,但不会进行挑选。 - -~~但是点击摇人的时候本来就会重新应用当前选好的筛选条件,所以这个按钮其实就是做来好看的。~~ - -### 为了防止被搞心态,不会出现连续抽到两个一样的人的情况。~~因为懒得写动画所以如果连续抽到两个一样的人就几乎看不出来了~~ - -## 隐藏功能:使用config.data文件对指定编号的人员进行指定概率编辑 - -~~究竟是什么居心的人才想让我开发这么一个鬼功能~~ - -![image](https://user-images.githubusercontent.com/10991308/200277374-0ff24e74-53d6-4d22-b513-bccc9f1af241.png) -![image](https://user-images.githubusercontent.com/10991308/200277421-a81b11a2-eec2-4373-957a-37dc134ef0b8.png) - -### 在相同目录下编辑一个config.data文件 -### 如果程序没有检测到文件,什么都不会发生 -### 如果检测到了,自动加隐藏属性并读取文件 -### config.data需要符合以下语法: -#### 1. 由N行组成 -#### 2. 每一行对应一位需要更改概率的序号 -#### 3. 每一行的内容为 `X,+/-/0` 即需要编辑的序号加上一个英文字符逗号加上英文字符+或者-或者数字0 -#### 4. 请再看一遍`3.`并确保你记住了每一个词 -#### 5. 如果输入了`+`,那么该序号被抽到的概率增加(前提是满足由班级选择器控制的筛选条件),且针对这些人的防搞心态保护失效。具体增加方法为每次抽人都有5% * (被标记为‘+’的人的人数)的概率只在被标记为‘+’的人中抽取,这个总概率的上限为30%。 -#### 6. 如果输入了`-`,那么该序号被抽到的概率减少。具体减少方法是每次抽人都有8% * (被标记为‘-’的人的人数)直接排除掉这些被标记的人。这个概率的上限是40%。 -#### 7. 如果输入了`0`,那么该序号便会被拒绝录入。即数据库中虽然存在该编号,但是程序不会将其视为可被抽取的对象。 -#### 8. 如欲更改配置,仅需在保存了更改后的配置文件后重启点名器程序即可。 diff --git a/.history/点名器_20221107012031.pyw b/.history/点名器_20221107012031.pyw deleted file mode 100644 index b4dd851..0000000 --- a/.history/点名器_20221107012031.pyw +++ /dev/null @@ -1,189 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui = Tk() - -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -gui_size = "620x200" -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在', parent=gui) - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols), parent=gui) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -gui.title("点名器") -gui.geometry(gui_size) -gui.resizable(0,0) -gui.configure(bg = "white") - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175501.pyw b/.history/点名器_20221107175501.pyw deleted file mode 100644 index e59186e..0000000 --- a/.history/点名器_20221107175501.pyw +++ /dev/null @@ -1,189 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.title("点名器") -gui.geometry(gui_size) -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在', parent=gui) - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols), parent=gui) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175513.pyw b/.history/点名器_20221107175513.pyw deleted file mode 100644 index 38f81d4..0000000 --- a/.history/点名器_20221107175513.pyw +++ /dev/null @@ -1,189 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.title("点名器") -gui.geometry(gui_size) -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175603.pyw b/.history/点名器_20221107175603.pyw deleted file mode 100644 index 38acc12..0000000 --- a/.history/点名器_20221107175603.pyw +++ /dev/null @@ -1,192 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.title("点名器") -gui.geometry("0x0") -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - - -gui.geometry("0x0") - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175606.pyw b/.history/点名器_20221107175606.pyw deleted file mode 100644 index 0d89a45..0000000 --- a/.history/点名器_20221107175606.pyw +++ /dev/null @@ -1,191 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.title("点名器") -gui.geometry("0x0") -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -gui.geometry("0x0") - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175614.pyw b/.history/点名器_20221107175614.pyw deleted file mode 100644 index 6b2ae32..0000000 --- a/.history/点名器_20221107175614.pyw +++ /dev/null @@ -1,191 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.title("点名器") -gui.geometry("0x0") -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -gui.geometry(gui_size) - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175730.pyw b/.history/点名器_20221107175730.pyw deleted file mode 100644 index ec5ee47..0000000 --- a/.history/点名器_20221107175730.pyw +++ /dev/null @@ -1,190 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.withdraw() -gui.title("点名器") -gui.geometry(gui_size) -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175743.pyw b/.history/点名器_20221107175743.pyw deleted file mode 100644 index 175c605..0000000 --- a/.history/点名器_20221107175743.pyw +++ /dev/null @@ -1,192 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.withdraw() -gui.title("点名器") -gui.geometry(gui_size) -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -gui.deiconify(); - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175744.pyw b/.history/点名器_20221107175744.pyw deleted file mode 100644 index 19cfc98..0000000 --- a/.history/点名器_20221107175744.pyw +++ /dev/null @@ -1,192 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.withdraw() -gui.title("点名器") -gui.geometry(gui_size) -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -gui.deiconify() - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file diff --git a/.history/点名器_20221107175745.pyw b/.history/点名器_20221107175745.pyw deleted file mode 100644 index 19cfc98..0000000 --- a/.history/点名器_20221107175745.pyw +++ /dev/null @@ -1,192 +0,0 @@ -import xlrd as excel -from tkinter import * -import tkinter.messagebox as msgbox -import random -import sys -import win32con, win32api - -gui_size = "620x200" - -gui = Tk() - -gui.withdraw() -gui.title("点名器") -gui.geometry(gui_size) -gui.resizable(0,0) -gui.configure(bg = "white") -class Student(object): - name = "" - subject = "" - id = "" - class_name = "" - - def __init__(self,id,class_name,subject,name): - self.id = id - self.class_name = class_name - self.subject = subject - self.name = name - -protection_override = False -up_percent = 30 -down_persent = 40 -filename = "names.xls" -configname = "config.data" -elim_rows = 1 -percent_override = True - -try: - excel_data = excel.open_workbook(filename) - table = excel_data.sheets()[0] - win32api.SetFileAttributes(filename,win32con.FILE_ATTRIBUTE_HIDDEN) -except FileNotFoundError: - msgbox.showerror('找不到数据库文件', '在相同目录下未能找到 names.xls 文件,请确认您的文件存在') - sys.exit() - -try: - cols = table.ncols - rows = table.nrows - assert cols == 4 - assert rows > 1 -except AssertionError: - msgbox.showerror('数据库文件格式不正确', '数据库文件内行/列数不合法,请确认数据库文件拥有超过1的行数和等于4的列数,当前行数:' + str(rows) + ' 当前列数:' + str(cols)) - sys.exit() - -elim_id = [] -up_id = [] -down_id = [] - -try: - with open(configname,'r') as file: - win32api.SetFileAttributes(configname,win32con.FILE_ATTRIBUTE_HIDDEN) - config = file.read().splitlines() - for unit in config: - temp = unit.split(",") - if temp[1] == '0': - elim_id.append(int(temp[0])) - elif temp[1] == '+': - up_id.append(int(temp[0])) - elif temp[1] == "-": - down_id.append(int(temp[0])) - else: - pass -except: - percent_override = False - -up_percent = len(up_id) * 5 if len(up_id) <= 6 else 30 -down_percent = len(down_id) * 8 if len(down_id) <= 5 else 40 - -gui.deiconify() - -students = [] -classes = [] -subjects = [] -filter = [] - -last_choice = "" - -# print("读取数据库成功:" + str(cols) + "列 " + str(rows) + "行") - -for i in range(elim_rows,rows): - tmp_list = [str(table.cell_value(i,j)) for j in range(0,cols)] - if (int(float(tmp_list[0])) not in elim_id): - student = Student(tmp_list[0],tmp_list[1],tmp_list[2],tmp_list[3]) - students.append(student) - -cur_stu = [] - -cur_stu = students[:] - -for student in students: - if student.class_name not in classes: - classes.append(student.class_name) - if student.subject not in subjects: - subjects.append(student.subject) - -cur_name = StringVar() - -def upd_name(name): - cur_name.set(name) - -upd_name("") - -listbox = Listbox(gui, selectmode = MULTIPLE, height = 5) - -for tmp_class in classes: - listbox.insert("end",tmp_class) - -def sel_class(flag = 1): - global filter, listbox, classes, cur_stu, students - filter.clear() - for selection in listbox.curselection(): - # print(selection) - filter.append(classes[selection]) - # print(filter) - if filter: - if flag: - msgbox.showinfo('班级选择已应用', '已应用当前班级选择', parent=gui) - cur_stu.clear() - for student in students: - if student.class_name in filter: - # print(student.name) - cur_stu.append(student) - else: - if flag: - msgbox.showwarning('班级选择已应用', '当前设置会选择所有班级的名单,这样对吗?', parent=gui) - filter = classes[:] - cur_stu = students[:] - -def choose(): - global last_choice, cur_stu - sel_class(0) - # 触发30%概率,从up中挑选 - if (random.randint(1,100) < up_percent and percent_override): - protection_override = True; - temp = [] - for student in cur_stu: - if int(float(student.id)) in up_id: - temp.append(student) - cur_stu = temp[:] - elif (random.randint(1,100) < down_persent and percent_override): - protection_override = True; - temp = []; - for student in cur_stu: - if int(float(student.id)) not in down_id: - temp.append(student) - cur_stu = temp[:] - else: - protection_override = False - - if not cur_stu: - protection_override = False - sel_class(0) - - choice = random.choice(cur_stu) - # print(choice.name) - counter = 0; - while (last_choice == choice.name and (not protection_override)) or choice.id in elim_id: - choice = random.choice(cur_stu) - counter = counter + 1 - if counter >= 100: - break - # print(choice.name) - upd_name(choice.name) - class_label.config(text = choice.class_name) - subject_label.config(text = choice.subject) - last_choice = choice.name - -startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white") - -setclass = Button(gui, text = "应用班级选用", font = ("宋体", 17), height = 2, command = sel_class, bg = "white") - -name_label = Label(gui, textvariable = cur_name, font = ("宋体", 30, "bold"), width = 20, bg = "white", fg = "blue") -class_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") -subject_label = Label(gui, text = "", font = ("宋体", 15), width = 20, bg = "white") - -class_label.grid(row = 2, column = 1, sticky = N+S+E+W) -subject_label.grid(row = 2, column = 2, sticky = N+S+E+W) -name_label.grid(row = 1, column = 1, sticky = N+S) -listbox.grid(row = 1, column = 2, sticky = N+S) -startrandom.grid(row = 3, column = 1, sticky = N+S+E+W) -setclass.grid(row = 3, column = 2, sticky = N+S+E+W) - -gui.mainloop() \ No newline at end of file