点名程序 签到+点名+滚动+音乐

点名程序 签到+点名+滚动+音乐

#!/usr/bin/env python
# coding: utf-8

# In[13]:


import tkinter as tk
import tkinter as Tkinter
from tkinter import *
import tkinter.messagebox
import random
import pandas as pd
import pygame
import sqlite3



# 签到窗口

if __name__ == '__main__':  # 如果模块是被直接运行的,则代码块被运行,如果模块是被导入的,则代码块不被运行。
    window = Tkinter.Tk()
    window.title('签到系统')
    # window.geometry('500x300')
    window.geometry('450x320+250+15')
    # bg_label = Label(window, width=70, height=24, bg='#ECf5FF')
    bg_label = Label(window, width=70, height=24)
    bg_label.place(anchor=NW, x=0, y=0)

    var1 = StringVar(value='签到')

    show_label1 = Label(window, textvariable=var1, justify='left', anchor=CENTER, width=17, height=3,
                       font='华文行楷 -40 bold', foreground='black')
    show_label1.place(anchor=NW, x=30, y=20)
    
    text1 = Label(window, text='学号:').place(anchor=NW, x=100, y=120)
    text2 = Label(window, text='姓名:').place(anchor=NW, x=100, y=170)
    
    v1 = StringVar()
    v2 = StringVar()
    e1 = Entry(window, textvariable=v1) # Entry 是 Tkinter 用来接收字符串等输入的控件.
    e2 = Entry(window, textvariable=v2)
    
    e1.place(anchor=NW, x=150, y=120)
    e2.place(anchor=NW, x=150, y=170)
    
    button1=Button(window, text='签到', width=10, command=lambda: [consql()]) .place(anchor=NW, x=100, y=250)
    button2=Button(window, text='退出', width=10, command=window.quit) .place(anchor=NE, x=350, y=250)

    window.mainloop()
    
name = []
def consql():

    a = "%s" % e1.get()
    b = "%s" % e2.get()
    conn = sqlite3.connect("studentsinfo.db")  #连接数据库
    cursor = conn.cursor()   #创建一个游标cursor 
    sql = "create table if not exists student (id varchar(20) primary key not null, name varchar(30));"
    cursor.execute(sql)
    sql = "insert Or Replace INTO student (id,name) VALUES ('{}','{}')".format(a, b)
    cursor.execute(sql)
    cursor.close()
    conn.commit()
    window.destroy()
    
    
    
sql = 'select * from student'
conn = sqlite3.connect('studentsinfo.db')
cursor = conn.cursor()
values = cursor.execute(sql)
for i in values:
    # print(i)
    for s in range(len(i)):
        if s % 2 != 0:
            s = str(i[s-1])+' '+i[s]
            name.append(s)
   

    


going = True  # 表示是否可以继续滚动(递归)显示下一个名额
is_run = False  # 表示当前抽奖器是否在运行


def lottery_roll(var1):
    global going
    show_member = random.choice(name)  # 随机选取姓名
    var1.set(show_member)  # var1 显示抽取出来的姓名
    if going:  # going=True
        window.after(50, lottery_roll, var1)  # 每50毫秒循环一次
    else: 
        result = tkinter.messagebox.showinfo(title='最终结果!', message='恭喜 {} !!!'.format(show_member))  # 弹窗显示恭喜+抽取出来的姓名
        going = True
        return  # 跳出def


def lottery_start(var1):
    pygame.mixer.init()
    pygame.mixer.music.load(r"D:/Python数据处理/A2A - 巴啦啦小魔仙 [mqms].mp3")      #路径
    global is_run
    if is_run:  # is_run = True
        return  # 跳出def
    is_run = True
    lottery_roll(var1)  # 执行循环抽取姓名的执行语句
    pygame.mixer.music.play(loops=4)      #音乐开始  pygame.mixer.music.play(loops,start)   loops是循环播放,start是开始位置(0-1)
    pygame.mixer.music.set_volume(0.7)    #控制音乐声音的大小


def lottery_end():
    global going, is_run
    if is_run:
        going = False
        is_run = False
        pygame.mixer.music.stop()  


if __name__ == '__main__':  # 如果模块是被直接运行的,则代码块被运行,如果模块是被导入的,则代码块不被运行。
    window = Tkinter.Tk()
    window.title('点名:')
    window.geometry('450x320+250+15')
    bg_label = Label(window, width=70, height=24)
    bg_label.place(anchor=NW, x=0, y=0)

    var1 = StringVar(value='谁会是天选之子')

    show_label1 = Label(window, textvariable=var1, justify='left', anchor=CENTER, width=17, height=3,
                       font='华文行楷 -40 bold', foreground='black')
    show_label1.place(anchor=NW, x=30, y=20)

    button1 = Button(window, text='开始', command=lambda: lottery_start(var1), width=14, height=2, bg='#A8A8A8',
                     font='华文仿宋 -18 bold')
    button1.place(anchor=NW, x=32, y=175)

    button2 = Button(window, text='结束', command=lambda: lottery_end(), width=14, height=2, bg='#A8A8A8',
                     font='华文隶书 -18 bold')
    button2.place(anchor=NW, x=232, y=175)

    window.mainloop()




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值