資源簡介
Python寫的一個簡單的抽簽軟件,可以實現比賽的隨機抽簽,人員可以在excel中進行修改
代碼片段和文件信息
#?-*-?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??抽簽\name.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
- 上一篇:python 手勢識別
- 下一篇:python編程初學者指南相關軟件和源代碼
評論
共有 條評論