首页 > 编程语言 >python学习记录:学生点名系统源码

python学习记录:学生点名系统源码

时间:2022-10-17 15:23:52浏览次数:48  
标签:点名 name python window 源码 var run col png

 

学生点名系统

# coding=utf-8

import tkinter as tk

from tkinter import *

import random

import time

import openpyxl

 

is_run = False

 

 

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

 

 

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

 

 

if __name__ == '__main__':

    window = tk.Tk()

    window.geometry('600x400+400+180')

    window.title('\t 学 生 点 名 系 统 (琴棋书画)')

    # 添加背景图片

    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()

标签:点名,name,python,window,源码,var,run,col,png
From: https://www.cnblogs.com/qlsh/p/16799298.html

相关文章

  • python学习记录;笔趣阁小说全文下载工具爬虫源码
    笔趣阁小说全本下载工具#导入模块importrequestsimportparselfromlxmlimportetreeimportreimportpandasaspdimportdatetimeimporttimefromtqdmimpor......
  • Python3爬虫中Selenium的用法详解
    Selenium是一个自动化测试工具,利用它可以驱动浏览器执行特定的动作,如点击、下拉等操作,同时还可以获取浏览器当前呈现的页面的源代码,做到可见即可爬。对于一些JavaScript动......
  • js 简单封装一个像python中的range函数
    functionrange(start,end,step){letarr=[];for(leti=start;i<end;i++){if(i%step==0){arr.push(i)}}returnarr;}letarr=range(0,60,5);conso......
  • ConcurrentHashMap源码,看我这篇就够了
    思考:HashTable是线程安全的,为什么不推荐使用?HashTable是一个线程安全的类,它使用synchronized来锁住整张Hash表来实现线程安全,即每次锁住整张表让线程独占,相当于所有线程进......
  • ConcurrentHashMap源码,看我这篇就够了
    持续创作,加速成长!这是我参与「掘金日新计划·10月更文挑战」的第5天,点击查看活动详情思考:HashTable是线程安全的,为什么不推荐使用?HashTable是一个线程安全的类,它使用s......
  • 日常便利-使用Python制作文件批量处理的exe
    序偶尔遇见要对文件名批量修改,部分文件名替换时候场景。思路是遍历文件名,然后对每个文件名重命名替换,打包成exePython代码importostry:file_dir=input(......
  • Python F + 双引号表达式【格式化输出】
    参考链接:https://blog.csdn.net/weixin_47702737/article/details/112756957主要用于格式化输出,setting=f"{args.env}_{args.seed}"buffer_name=f"{args.buffer_nam......
  • vue源码分析-响应式系统(一)
    从这一小节开始,正式进入Vue源码的核心,也是难点之一,响应式系统的构建。这一节将作为分析响应式构建过程源码的入门,主要分为两大块,第一块是针对响应式数据props,methods,da......
  • 直播商城系统源码,实现最简单最基本的轮播图样式
    直播商城系统源码,实现最简单最基本的轮播图样式一、H5的布局可以使用自己的图片,需要注意路径​ <divclass="banner"><ulclass="imgList"><li><imgsrc="1.png"/></l......
  • vue源码分析-响应式系统(二)
    为了深入介绍响应式系统的内部实现原理,我们花了一整节的篇幅介绍了数据(包括data,computed,props)如何初始化成为响应式对象的过程。有了响应式数据对象的知识,上一节的后......