from PySide2.QtWidgets import QApplication, QMainWindow, QMessageBox, QWidget
from PySide2.QtUiTools import QUiLoader
from PySide2.QtGui import QIcon
import random
import ctypes
class Main:
def __init__(self):
# 加载ui文件
self.ui = QUiLoader().load('random_machine.ui')
# 创建一个空列表,用于存储生成的指定数字
self.number_list = []
# 设置次数
self.count = 0
# 历史记录 仅限用于测试输出打印,并没用实际的作用效果
self.history = []
# 设置标识符,用来判断重置按钮是否被点击 False表示默认没有点击
self.reset_clicked = False
# 创建一个空字符串,用于存储显示到界面的历史记录信息
self.information = "*"*50 + "重新启动了程序" + "*"*50
# 执行主程序,即自动调用各种方法
self.action()
# 设计一个方法,用于自动调用各种方法
def action(self):
# 每重启程序一次就往日志文件加一行分割符
self.write_text(self.information)
# 获取起始数字
self.first_number = self.first_textEdit()
# 获取结束数字
self.last_number = self.last_textEdit()
# 调用方法,生成指定的数组
self.get_number_list()
# 按钮点击事件
self.button_action()
# 按钮点击事件
def button_action(self):
# 开始按钮
self.ui.start_pushButton.clicked.connect(self.random_machine)
# 重置按钮
self.ui.reset_pushButton.clicked.connect(self.reset_button)
# 清空历史记录按钮
self.ui.clear_history_pushButton.clicked.connect(self.clear_history_pushButton)
# 默认按钮
self.ui.default_pushButton.clicked.connect(self.default_pushButton)
# 抽取数字
def random_machine(self):
print(f"当前的重置按钮状态:{self.reset_clicked}")
# 一开始就判断起始数字和结束数字是否被修改 如果修改就将状态改为False
# 因为如果不调用isNumber_modify()的话,那么一开始就要点击重置按钮 这样用户体验感就不是很好
self.isNumber_modify()
# 获取到最新的开始数字
first_number = self.first_textEdit()
# 获取最新的结束数字
last_number = self.last_textEdit()
# 判断用户给的区间是否合理,即是否起始数字小于结束数字
if first_number > last_number:
QMessageBox.about(self.ui,
"温馨提示",
f"请保证起始数字小于结束数字",
)
# 记录 历史记录
self.information = "起始数字大于结束数字"
self.history.append(self.information)
else:
if self.reset_clicked == False:
# 如果起始数字和结束数字被修改了,那就将开始按钮禁用和提示用户点击重置按钮
if self.first_number!=first_number or self.last_number!= last_number:
QMessageBox.about(self.ui,
"温馨提示",
f"源源发现你修改了起始或者结束数字,请先点击重置按钮",
)
# 将开始按钮禁用
self.ui.start_pushButton.setEnabled(False)
# 记录 历史记录
self.information = "你修改了起始或者结束数字"
self.history.append(self.information)
else:
# 根据用户指定的次数 进行循环
self.count += 1
# 如果原始数据还有数据
if len(self.number_list) != 0:
# 调用 删除已经随机生成的数字 方法
number = self.remote_number(self.count)
self.show_number(number)
# 判断当前次数是否大于结束数字,如果大于就说明数据已经抽取完毕了
if self.count >= last_number+1:
QMessageBox.about(self.ui,
"温馨提示",
f"本次抽取的数字已完成,请点击重置按钮和重新设置数字重新开始",
)
# 将开始按钮禁用
self.ui.start_pushButton.setEnabled(False)
# 记录 历史记录
self.information = "本次抽取的数字已完成"
self.history.append(self.information)
# 显示历史记录
self.show_history()
# 将历史记录写入日志文件
self.write_text()
print(self.history)
# 设计一个方法,用于生成指定的数据
def get_number_list(self):
# 获取起始数字
first_number = self.first_textEdit()
# 获取结束数字
last_number = self.last_textEdit()
# 将count值设为0,重新开始生成新数据
self.count = 0
for i in range(first_number, last_number + 1):
self.number_list.append(i)
print(f"开始的数据:{self.number_list}")
print("*" * 100)
# 设计一个方法,用于删除已经随机生成的数字
def remote_number(self, count):
# 根据已有的列表 随机生成数
number = random.choice(self.number_list)
# 根据随机生成的数 从 原始数据中 删除
self.number_list.remove(number)
self.information = f"第{count}次随机生成的数是:{number}"
self.history.append(self.information)
print(f"第【{count}】次删除了:{number}")
print(f"第【{count}】次删除后的数据:{self.number_list}")
# 判断原始数据中是否还包含删除过的数据
is_contain = number in self.number_list
print(f"(number_list是否包含{number}:{is_contain})")
return number
# 获取起始数字
def first_textEdit(self):
value = self.ui.first_textEdit.toPlainText()
# 判断用户是否给了空字符串
self.is_user_input_Empty(value)
if " " or "\n" in value:
value = self.ui.first_textEdit.toPlainText().replace(" ", "").replace("\n", "")
print(f"起始数字:{value}")
return int(value)
# 获取结束数字
def last_textEdit(self):
value = self.ui.last_textEdit.toPlainText()
# 判断用户是否给了空字符串
self.is_user_input_Empty(value)
# 判断用户给的字符串是否有空格或者换行
if " " or "\n" in value:
value = self.ui.last_textEdit.toPlainText().replace(" ", "").replace("\n", "")
print(f"结束数字:{value}")
return int(value)
# 展示生成的随机数
def show_number(self,number):
self.ui.main_textEdit.setText(str(number))
# 显示历史记录
def show_history(self):
self.ui.history_plainTextEdit.appendPlainText(str(self.information)+"\n")
# 重置按钮
def reset_button(self):
# 当重置按钮被点击了,就将flag设置为True
self.reset_clicked = True
first_number = self.first_textEdit()
last_number = self.last_textEdit()
self.first_number = first_number
self.last_number = last_number
print("*"*100)
print("你点击了重置按钮")
# 记录 历史记录
self.information = f"===你点击了重�
没有合适的资源?快使用搜索试试~ 我知道了~
基于python3.7+pyside2搭建的简单的随机抽号机
共146个文件
dll:86个
qm:23个
pyd:16个
需积分: 23 2 下载量 189 浏览量
2022-07-16
18:36:07
上传
评论 1
收藏 43.34MB ZIP 举报
温馨提示
这就是个简单随机抽号机,类似于我们学生时代,经常被老师喜欢随机点名回答问题的。 使用于有python基础的小白,以及对pyside2这个库有所了解的小白
资源详情
资源评论
资源推荐
收起资源包目录
基于python3.7+pyside2搭建的简单的随机抽号机 (146个子文件)
qt.conf 21B
opengl32sw.dll 19.95MB
Qt5Gui.dll 6.69MB
Qt5Core.dll 5.75MB
Qt5Widgets.dll 5.25MB
Qt5Pdf.dll 4.27MB
d3dcompiler_47.dll 4.26MB
Qt5Quick.dll 3.96MB
python37.dll 3.58MB
Qt5Qml.dll 3.43MB
libGLESv2.dll 3.23MB
libcrypto-1_1.dll 3.23MB
Qt5VirtualKeyboard.dll 2MB
qdirect2d.dll 1.47MB
qwindows.dll 1.41MB
Qt5Network.dll 1.28MB
ucrtbase.dll 1020KB
qminimal.dll 830KB
qoffscreen.dll 742KB
libssl-1_1.dll 670KB
MSVCP140.dll 604KB
qwebp.dll 503KB
qwebgl.dll 476KB
Qt5QmlModels.dll 433KB
Qt5DBus.dll 431KB
qjpeg.dll 416KB
qtiff.dll 386KB
Qt5Svg.dll 328KB
shiboken2.abi3.dll 250KB
Qt5Xml.dll 213KB
pyside2.abi3.dll 158KB
Qt5WebSockets.dll 151KB
qwindowsvistastyle.dll 146KB
VCRUNTIME140.dll 88KB
qxdgdesktopportal.dll 72KB
python3.dll 58KB
qgenericbearer.dll 57KB
qicns.dll 49KB
qtvirtualkeyboardplugin.dll 48KB
qsvgicon.dll 46KB
VCRUNTIME140_1.dll 43KB
qgif.dll 43KB
qico.dll 42KB
qpdf.dll 37KB
qsvg.dll 36KB
qtga.dll 36KB
qwbmp.dll 34KB
MSVCP140_1.dll 31KB
libEGL.dll 29KB
api-ms-win-crt-math-l1-1-0.dll 28KB
api-ms-win-crt-string-l1-1-0.dll 25KB
api-ms-win-crt-stdio-l1-1-0.dll 25KB
api-ms-win-crt-runtime-l1-1-0.dll 23KB
api-ms-win-crt-convert-l1-1-0.dll 23KB
api-ms-win-core-file-l1-1-0.dll 22KB
api-ms-win-core-localization-l1-2-0.dll 21KB
api-ms-win-crt-time-l1-1-0.dll 21KB
api-ms-win-core-processthreads-l1-1-0.dll 21KB
api-ms-win-crt-filesystem-l1-1-0.dll 21KB
api-ms-win-core-synch-l1-1-0.dll 21KB
api-ms-win-core-processenvironment-l1-1-0.dll 20KB
api-ms-win-core-sysinfo-l1-1-0.dll 20KB
api-ms-win-crt-process-l1-1-0.dll 20KB
api-ms-win-crt-conio-l1-1-0.dll 20KB
api-ms-win-crt-heap-l1-1-0.dll 20KB
api-ms-win-core-processthreads-l1-1-1.dll 19KB
api-ms-win-core-libraryloader-l1-1-0.dll 19KB
api-ms-win-core-rtlsupport-l1-1-0.dll 19KB
api-ms-win-crt-environment-l1-1-0.dll 19KB
api-ms-win-crt-utility-l1-1-0.dll 19KB
api-ms-win-core-console-l1-1-0.dll 19KB
api-ms-win-crt-locale-l1-1-0.dll 19KB
api-ms-win-core-heap-l1-1-0.dll 19KB
api-ms-win-core-memory-l1-1-0.dll 19KB
api-ms-win-core-synch-l1-2-0.dll 19KB
api-ms-win-core-errorhandling-l1-1-0.dll 19KB
api-ms-win-core-interlocked-l1-1-0.dll 19KB
api-ms-win-core-timezone-l1-1-0.dll 19KB
api-ms-win-core-namedpipe-l1-1-0.dll 19KB
api-ms-win-core-datetime-l1-1-0.dll 19KB
api-ms-win-core-handle-l1-1-0.dll 19KB
api-ms-win-core-string-l1-1-0.dll 19KB
api-ms-win-core-debug-l1-1-0.dll 19KB
api-ms-win-core-file-l1-2-0.dll 19KB
api-ms-win-core-util-l1-1-0.dll 19KB
api-ms-win-core-file-l2-1-0.dll 19KB
api-ms-win-core-profile-l1-1-0.dll 18KB
main.exe 1.43MB
main.exe 1.43MB
xref-main.html 265KB
main.exe.lnk 969B
main.exe.lnk 969B
main.exe.manifest 1KB
main.pkg 1.15MB
QtWidgets.pyd 6MB
QtGui.pyd 3.65MB
QtCore.pyd 3.3MB
unicodedata.pyd 1.02MB
QtNetwork.pyd 931KB
QtUiTools.pyd 553KB
共 146 条
- 1
- 2
苏九黎
- 粉丝: 80
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0