mirror of
https://github.com/HChaZZY/Random-Picker.git
synced 2025-12-06 10:33:50 +08:00
加入资源文件存在性测试 没有询问用户加载默认设置
This commit is contained in:
35
点名器.pyw
35
点名器.pyw
@@ -7,8 +7,15 @@ import win32con, win32api
|
||||
import winsound
|
||||
import time
|
||||
|
||||
filename = "./data/names.xls"
|
||||
configname = "./data/config.data"
|
||||
selname = "./assets/sel.wav"
|
||||
procname = "./assets/proc.wav"
|
||||
iconname = "./assets/点名器.ico"
|
||||
gui_size = "620x200"
|
||||
|
||||
sound = True
|
||||
|
||||
gui = Tk()
|
||||
|
||||
gui.withdraw()
|
||||
@@ -16,7 +23,26 @@ gui.title("点名器")
|
||||
gui.geometry(gui_size)
|
||||
gui.resizable(0,0)
|
||||
gui.configure(bg = "white")
|
||||
gui.iconbitmap("./assets/点名器.ico")
|
||||
|
||||
try:
|
||||
file = open(iconname)
|
||||
file.close()
|
||||
gui.iconbitmap(iconname)
|
||||
except IOError:
|
||||
if not msgbox.askokcancel('资源文件错误', '在./assets目录下未能找到 点名器.ico 文件,点击「确定」将加载默认图标,点击「取消」以关闭程序'):
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
file = open(selname)
|
||||
file.close()
|
||||
file = open(procname)
|
||||
file.close()
|
||||
except IOError:
|
||||
if msgbox.askokcancel('资源文件错误', '在./assets目录下未能找到音频文件,点击「确定」将关闭声音,点击「取消」以关闭程序'):
|
||||
sound = False
|
||||
else:
|
||||
sys.exit()
|
||||
|
||||
class Student(object):
|
||||
name = ""
|
||||
subject = ""
|
||||
@@ -32,10 +58,6 @@ class Student(object):
|
||||
protection_override = False
|
||||
up_percent = 30
|
||||
down_persent = 40
|
||||
filename = "./data/names.xls"
|
||||
configname = "./data/config.data"
|
||||
selname = "./assets/sel.wav"
|
||||
procname = "./assets/proc.wav"
|
||||
elim_rows = 1
|
||||
percent_override = True
|
||||
|
||||
@@ -180,7 +202,8 @@ def choose():
|
||||
class_label.config(text = choice.class_name)
|
||||
subject_label.config(text = choice.subject)
|
||||
last_choice = choice.name
|
||||
winsound.PlaySound(selname, winsound.SND_ASYNC | winsound.SND_FILENAME)
|
||||
if sound:
|
||||
winsound.PlaySound(selname, winsound.SND_ASYNC | winsound.SND_FILENAME)
|
||||
|
||||
startrandom = Button(gui, text = "立刻摇人!", font = ("宋体", 17, "bold"), height = 2, fg = "red", command = choose, bg = "white")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user