Python写的一个简单的抽签软件,可以实现比赛的随机抽签,人员可以在excel中进行修改
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-11-09 13:29 抽签
文件 1131299 2018-08-17 09:54 抽签1.png
文件 9285438 2018-08-17 09:28 抽签code.exe
文件 4749 2018-08-17 11:49 抽签code.py
文件 10959 2018-08-17 01:28 抽签
ame.xlsx
目录 0 2018-11-09 13:29 抽签\__pycache__
文件 3498 2018-08-17 09:28 抽签\__pycache__code.cpython-35.pyc
文件 8252530 2018-08-17 01:24 抽签抽签.exe
# -*- coding: cp936 -*-
import xlrd
import xlwt
import random
import os
import sys
import threading
import time
from tkinter import *
# 配置加载路径
config_name = ‘name‘
# determine if application is a script file or frozen exe
if getattr(sys ‘frozen‘ False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.dirname(__file__)
#config_path = os.path.join(application_path config_name)
config_path = application_path
#界面程序初始化
root = Tk()
root.title(“抽签“)
root.geometry(‘800x600‘)
Label(root text=‘比赛抽签‘ font=(‘HeiTi‘ 20)).pack()
frm = frame(rootheight = 600width = 800)
frm1 = frame(frm)
frm2 = frame(frm)
frm3 = frame(frm)
radioTxt= IntVar()
Radiobutton(frm2text = “男单“variable = radioTxtvalue = 1).grid(row = 0column = 0)
Radiobutton(frm2text = “女单“variable = radioTxtvalue = 2).grid(row = 0column = 1)
Radiobutton(frm2text = “双打“variable = radioTxtvalue = 3).grid(row = 0column = 2)
radioTxt.set(1)
frm2.pack(pady=10)
frm.pack()
#excel初始化
workbook=xlwt.Workbook(encoding=‘utf-8‘)
booksheet=workbook.add_sheet(‘Sheet 1‘ cell_overwrite_ok=True)
def read_excel():
getRadioValue= radioTxt.get()
print( getRadioValue )
#strName = “E:“+ “\“+ excelName +“.xlsx“
strName = config_path +“/name.xlsx“
ExcelFile=xlrd.open_workbook(strName)
#获取目标EXCEL文件sheet名
if getRadioValue == 1:
sheet=ExcelFile.sheet_by_name(‘Sheet1‘)
elif getRadioValue == 2:
sheet=ExcelFile.sheet_by_name(‘Sheet2‘)
else:
sheet=ExcelFile.sheet_by_name(‘Sheet3‘)
#获取整行或者整列的值
tempNameList=sheet.col_values(0)#第一列内容
tempSeedList=sheet.col_values(1)#第二列内容
return tempNameList tempSeedList
def GetRandomList():
nameListseedList = read_excel()
random.shuffle(nameList)
random.shuffle(seedList)
while ‘‘ in nameList:
nameList.remove(‘‘)
while ‘‘ in seedList:
seedList.remove(‘‘)
matchType = 1
if len(seedList) > 1:
matchType = 2
#print (seedList)
if matchType == 2:
for i in range(0len(seedList)):
nameList.insert(len(seedList)-2*i+1seedList[i])
#print (nameList)
return nameList matchType
def ChouQian():
nameListmatchType = GetRandomList()
lenth = len(nameList)
#left
#frm_L = frame(frm)
#清空
for i in range(0121):
for j in range(031):
Label(frm1 text =““ width = 15height = 1font=(‘微软雅黑‘ 15)).grid(row = i+1column = j)
#覆盖写入
if matchType == 1:
for i in range(0lenth2):
Label(frm1 text =nameList[i] width = 15height = 1font=(‘微软雅黑‘ 15)).grid(row = i+1column = 0)
else:
for i in range(0lenth4):
if i < (lenth -1):
Label(frm1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-11-09 13:29 抽签
文件 1131299 2018-08-17 09:54 抽签1.png
文件 9285438 2018-08-17 09:28 抽签code.exe
文件 4749 2018-08-17 11:49 抽签code.py
文件 10959 2018-08-17 01:28 抽签
ame.xlsx
目录 0 2018-11-09 13:29 抽签\__pycache__
文件 3498 2018-08-17 09:28 抽签\__pycache__code.cpython-35.pyc
文件 8252530 2018-08-17 01:24 抽签抽签.exe
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)