from tkinter import *
import random
import openpyxl
is_run = False
def insert_point():
var = input.get() #获取输入的信息
return var
def randomResult(list,num):
global is_run
result = random.sample(list, num)
var.set(result)
if is_run:
window.after(100, randomResult, list, num)
def finalResult():
global is_run
is_run = False
def randomRun(list):
global is_run
if is_run:#此部分用于避免多次点击开始造成程序重复执行的错误
return
is_run = True
num = insert_point()
if num:
num = int(num)
randomResult(list,num)
else:
is_run = False
def getPeopleList():
workbook = openpyxl.load_workbook("./peopleList.xlsx", data_only=True)
list = []
sheet = workbook[workbook.sheetnames[0]]
for row in range(2,sheet.max_row+1):
if sheet.cell(row=row,column=2).value == "":
continue
else:
list.append(sheet.cell(row=row,column=2).value)
return list
if __name__ == '__main__':
window = Tk()
window.geometry('500x290+250+150')
window.resizable(0,0)
window.title('抽奖小程序')
list = getPeopleList()
var = StringVar()
noteLable = Label(text="请输入抽奖人数:")
noteLable.place(anchor=NW, x=120, y=30)
input = Entry(window, show=None)
input.place(anchor=NW, x=240, y=30)
resultLable = Label(textvariable=var)
resultLable.place(anchor=NW, x=150, y=100)
startBt = Button(text="开始", command=lambda: randomRun(list=list))
confirmBt = Button(text="确定", command=lambda: finalResult())
startBt.place(anchor=NW, x=200, y=180)
confirmBt.place(anchor=NW, x=260, y=180)
window.mainloop()
# 输出日历界面
print("*" * 50)
print("欢迎使用【天天日历】v2.0")
# 接收用户输入的年份
year_int = int(input("请输入年份:\n"))
# 定义全局变量用于记录天数总和
sum = 0
if year_int >= 1917:
month_int = int(input("请输入月份\n"))
for year_every in range(1917, year_int): # 遍历从1917年到用户输入年份 用于计算到用户所输入年份共多少天
if (year_every % 4 == 0 and year_every % 100 != 0) or \
year_every % 400 == 0: # 如果是瑞年则366天否则平年365天
sum += 366
else:
sum += 365
for month_every in range(1, month_int): # 遍历月份用于计算由1月份到用户输入月份的总天数
if month_every == 4 or month_every == 6 or \
month_every == 9 or month_every == 11:
sum += 30
elif month_every == 2:
if (year_int % 1 == 0 and year_int % 100 != 0) or \
year_int % 400 == 0:
sum += 29
else:
sum += 28
else:
sum += 31
# 定义变量用于定义每个月的天数
day = 0
# 定义变量 用于计算当月第一天为周几
weak = sum % 7
print("日\t一\t二\t三\t四\t五\t六")
# 判断用户输入月份为多少天
if month_int == 4 or month_int == 6 or month_int == 9 or month_int == 11:
day = 30
elif month_int == 2:
if (year_int % 4 == 0 and year_int % 100 != 0) or \
year_int % 400 == 0:
day = 29
else:
day = 28
else:
day = 31
# 输出指定空格数让第一天与周几对齐
print("\t"*weak,end="")
i = 1
while i <= day: # 遍历用户查询月份
weakend = ((sum+i)-1)% 7
# 如果余数为6 换行否则输出空格
if weakend == 6:
print("%d" %i)
else:
print(i,end="\t")
i += 1
else:
print("系统正在维护暂时无法获取1917年之前的信息")