点名程序 签到+点名+滚动+音乐
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('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)
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)
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()
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:
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)
if going:
window.after(50, lottery_roll, var1)
else:
result = tkinter.messagebox.showinfo(title='最终结果!', message='恭喜 {} !!!'.format(show_member))
going = True
return
def lottery_start(var1):
pygame.mixer.init()
pygame.mixer.music.load(r"D:/Python数据处理/A2A - 巴啦啦小魔仙 [mqms].mp3")
global is_run
if is_run:
return
is_run = True
lottery_roll(var1)
pygame.mixer.music.play(loops=4)
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()