Teacher's Day is coming, I made a very useful student roll call system in Python

Teacher's Day is coming, I made a very useful student roll call system in Python

Teacher's Day is coming, I wish the great teachers a happy Teacher's Day!

foreword

There are many teachers among my relatives and friends. According to my survey, most of the current students are very active and will take the initiative to raise their hands to answer questions. However, there are also some bad situations. For example, the higher the grade, the fewer people who raise their hands actively. In some classes, it is usually a small number of active students who raise their hands, and some students never raise their hands.

A random student roll call system can help teachers solve these problems.

  • Random Roll calls a random student from the entire class so everyone has a chance to answer questions and promotes educational equity.

  • The roll call system has a rolling time of a few seconds, which will increase the tension of the students, so that the students who have deserted can quickly concentrate and play a role in supervising their learning.

  • If no students raise their hands, teachers don’t need to be embarrassed. The roll call system can be used as a “killer” for teachers.

In the actual situation, the students can take the initiative part of the time, and the roll call system can be used flexibly for part of the time.

Video display of roll call system

This article uses Python to implement a very useful student roll call system, and the packaged system download method is provided at the end of the article. Take a look at the effect first:

Teacher's Day, use Python to make a very useful roll call system

Implementation introduction

1. Read the excel sheet

openpyxl is a very convenient library for reading and writing excel files in Python, pip install openpyxl can be installed and used.

This article uses openpyxl to read all student names in excel.

def get_students_name():
    # 学生名单中需要有"姓名"列
    workbook = openpyxl.load_workbook('学生名单.xlsx')
    table = workbook.active
    rows, cols = table.max_row, table.max_column
    name_col = 0
    for col in range(cols):
        if table.cell(1, col + 1).value == '姓名':
            name_col = col
            break
    students_name = [table.cell(row+1, name_col+1).value for row in range(1, rows)
                     if table.cell(row+1, name_col+1).value is not None]
    return students_name

Openpyxl usage reference: Python uses the openpyxl module to read and write excel files

2. Build the system interface

tkinter is a very easy-to-use library for GUI programming in Python, and it is a standard library that does not need to be installed, just import it and use it.

In this paper, tkinter is used to build the interface of the student roll call system, and the roll call button and the roll call result are displayed on the interface.

if __name__ == '__main__':
    window = tk.Tk()
    window.geometry('600x400+400+180')
    window.title('\t 学 生 点 名 系 统 (公众号:小斌哥ge)')
    # 添加背景图片
    bg_png = tk.PhotoImage(file="背景图片.png")
    bg_label = Label(window, image=bg_png)
    bg_label.pack()
    # 添加显示框
    var = StringVar(value='公平 公正 公开')
    show_label1 = Label(window, textvariable=var, justify='left', anchor=CENTER, width=16,
                        height=2, font='楷体 -40 bold', foreground='white', bg='#1C86EE')
    show_label1.place(anchor=tk.NW, x=130, y=90)
    # 添加点名按钮
    button_png = tk.PhotoImage(file='button.png')
    button = Button(window, text='点 名', compound='center', font='楷体 -30 bold',
                    foreground='#9400D3', image=button_png,
                    command=lambda: call_lucky_student(var))
    button.place(anchor=NW, x=235, y=200)
    # 显示窗口
    window.mainloop()

3. Randomly select students

The random library is a library used to implement random functions in Python, and it is also the standard library of Python. It does not need to be installed and can be used by importing.

In this paper, random is used to randomly select a name from the student list, and combined with the time module to set the delay, the business logic function of the roll call button is realized.

def call_lucky_student(var):
    """点名"""
    global is_run
    if is_run:
        return
    is_run = True
    start = time.time()
    choice_student(var, start)


def choice_student(var, start):
    global is_run
    show_member = random.choice(get_students_name())
    name = show_member[0]
    for zi in show_member[1:]:
        name += ' ' + zi
    var.set(name)
    end = time.time()
    if is_run and end-start <= 5:
        window.after(30, choice_student, var, start)
    else:
        is_run = False
        return

Random usage reference: Use of common methods of Python random module

4. Package the code into an exe

The pyinstaller library is a library for packaging Python programs into exe executable files, which can be used after pip install pyinstaller.

This article uses pyinstaller to package the code of the roll call system into an exe file, so that the system can be sent to teachers for use, and it doesn't matter if you don't know programming.

Instructions for use and how to download

Instructions for use:

1. After downloading the system, unzip the file and save the entire folder to the computer (it is not recommended to put it on the desktop).

2. Open the student list excel form, enter the student name and student number into the form, and save. (Delete the dummy list for this article)

3. Find student.exe, right-click to create a desktop shortcut.

4. Double-click on the desktop to open the roll call system, and it can be used normally.

Download method:

The complete code and the packaged student roll call system can be obtained by clicking on the QR code below with WX, and then replying to the "roll call system" in the background.

The background image, button image, and test list of students needed to run the code can also be obtained together.

The above is the whole content of this article. If you like this student roll call system, please like, comment and favorite.

Related Reading:

Python uses Tkinter to implement a rolling lottery
Python uses Tkinter to implement a carousel lottery

Guess you like

Origin blog.csdn.net/weixin_43790276/article/details/126513893