-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturntable-simple-backup.py
117 lines (97 loc) · 4.15 KB
/
turntable-simple-backup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'turntable-simple.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import random
class Ui_Dialog(object):
def __init__(self):
self.num = 0 # use to store the random number
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.update_label)
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.setEnabled(True)
Dialog.resize(560, 600)
font = QtGui.QFont()
font.setFamily("ADMUI3Lg")
Dialog.setFont(font)
self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(130, 420, 300, 61))
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(20)
font.setBold(False)
font.setWeight(50)
self.buttonBox.setFont(font)
self.buttonBox.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.buttonBox.setLayoutDirection(QtCore.Qt.RightToLeft)
self.buttonBox.setAutoFillBackground(False)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Apply | QtWidgets.QDialogButtonBox.Discard)
self.apply_button = self.buttonBox.button(QtWidgets.QDialogButtonBox.Apply)
self.apply_button.setText("开始抽奖")
self.apply_button.setFont(font)
self.apply_button.clicked.connect(self.new_apply)
self.discard_button = self.buttonBox.button(QtWidgets.QDialogButtonBox.Discard)
self.discard_button.setText("停止抽奖")
self.discard_button.setFont(font)
self.discard_button.clicked.connect(self.new_discard)
self.buttonBox.setCenterButtons(True)
self.buttonBox.setObjectName("buttonBox")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(80, 130, 400, 200))
font = QtGui.QFont()
font.setFamily("阿里妈妈数黑体")
font.setPointSize(50)
font.setBold(True)
font.setWeight(75)
font.setKerning(False)
self.label.setFont(font)
self.label.setMouseTracking(False)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.retranslateUi(Dialog)
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "旭日工商管理学院2024年毕业晚会抽奖转盘"))
self.label.setText(_translate("Dialog", "抽奖编号"))
def show(self):
Dialog = QtWidgets.QDialog()
self.setupUi(Dialog)
Dialog.show()
return Dialog
def new_apply(self):
"""新的抽奖方法
1. self.label开始随机显示一个001-400的数字
2. 禁用按钮
"""
self.timer.start(3) # start the timer, update the label every 100 ms
self.apply_button.setEnabled(False)
self.discard_button.setEnabled(True)
def update_label(self):
self.num = random.randint(1, 400)
self.label.setText(str(self.num).zfill(3))
def new_discard(self):
"""新的回退抽奖方法
1. 点击按钮,将self.listView中最后一个中奖号码删除
2. 如果self.listView为空,则self.label显示"TextLabel"""
# if self.listView.count() > 0:
# self.listView.takeItem(self.listView.count() - 1)
# if self.listView.count() == 0:
# self.label.setText("TextLabel")
self.timer.stop()
self.apply_button.setEnabled(True)
self.discard_button.setEnabled(False)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication([])
ui = Ui_Dialog()
Dialog = ui.show()
sys.exit(app.exec_())