import pandas as pd
from PyQt5.QtGui import *
import time
from PyQt5 import QtCore,QtGui, QtWidgets
import base64
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5 import QtCore
import sys
import random
class QFileDialogDemo(QWidget):
def __init__(self):
super(QFileDialogDemo, self).__init__()
self.initUI()
def initUI(self):
self.resize(800, 600)
button_data = QPushButton(self)
button_data.setText("...")
button_data.setGeometry(QtCore.QRect(20, 20, 20, 20))
button_data.setStyleSheet("QPushButton{font-size:25px;font-family:'楷体';color:rgb(0,0,0,255);} ")
button_data.move(20, 60)
button_data.clicked.connect(self.UpLoadData)
button_data = QPushButton(self)
button_data.setText("开始抽奖")
button_data.setGeometry(QtCore.QRect(20, 20, 120, 40))
button_data.setStyleSheet("QPushButton{font-size:25px;font-family:'楷体';color:rgb(0,0,0,255);} ")
button_data.move(200, 40)
button_data.clicked.connect(self.choujiang)
self.grades_label = QLabel(self)
self.grades_label.setText("几等奖")
self.grades_label.move(60, 100)
self.grades = QLineEdit(self)
self.grades.setGeometry(QtCore.QRect( 170, 100, 100, 20))
self.renshu_label = QLabel(self)
self.renshu_label.setText("抽奖人数")
self.renshu_label.move(60, 140)
self.renshu = QLineEdit(self)
self.renshu.setGeometry(QtCore.QRect( 170, 140, 100, 20))
self.getgrenshu_label = QLabel(self)
self.getgrenshu_label.setText("获奖人员名单")
self.getgrenshu_label.move(60, 180)
self.getrenshu = QTextEdit(self)
self.getrenshu.setGeometry(QtCore.QRect( 170, 180, 400, 400))
self.df_yudu = QLabel(self)
self.df_yudu.setText("上传人员表格")
self.df_yudu.move(60, 60)
self.setwindowTitle('年会抽奖 ')
def UpLoadData(self):
try:
fname = QFileDialog.getopenFileName(self, 'open', "", '*xlsx', 'All Files(*)')
self.excel_path = fname
print(self.excel_path)
self.data=pd.read_excel(self.excel_path,sheet_name="参与抽奖人员")
print(self.data)
self.datalist=[]
for i in range(self.data.shape[0]):
self.datalist.append(i)
self.datalist.remove(0)
self.datalist.remove(1)
except Exception as e:
self.getrenshu.append("文件上传错误")
def choujiang(self):
try:
grades = int(self.grades.text())
chourenshu=int(self.renshu.text())
# 一等奖
if (grades == 1):
self.getrenshu.clear()
chourenshu=chourenshu-1
self.getrenshu.append(self.data.iloc[0, 2] + "编号为: " + str(self.data.iloc[0, 1]))
if(chourenshu>0):
chou_list = random.sample(self.datalist, chourenshu)
print("chou_list:", chou_list)
for haschou in chou_list:
self.datalist.remove(haschou)
print(self.datalist)
for renyuan in chou_list:
print(renyuan)
print("人员有: ", self.data.iloc[renyuan, 2])
self.getrenshu.append(self.data.iloc[renyuan, 2] + "编号为: " + str(self.data.iloc[renyuan, 1]))
# 神秘大奖
if (grades == 4):
self.getrenshu.clear()
chourenshu = chourenshu - 1
self.getrenshu.append(self.data.iloc[1, 2] + "编号为: " + str(self.data.iloc[1, 1]))
if (chourenshu > 0):
chou_list = random.sample(self.datalist, chourenshu)
print("chou_list:", chou_list)
for haschou in chou_list:
self.datalist.remove(haschou)
print(self.datalist)
for renyuan in chou_list:
print(renyuan)
print("人员有: ", self.data.iloc[renyuan, 2])
self.getrenshu.append(self.data.iloc[renyuan, 2] + "编号为: " + str(self.data.iloc[renyuan, 1]))
# 其余奖项
if (grades == 2 or grades == 3 or grades == 0):
self.getrenshu.clear()
if (chourenshu > 0):
chou_list = random.sample(self.datalist, chourenshu)
print("chou_list:", chou_list)
for haschou in chou_list:
self.datalist.remove(haschou)
print(self.datalist)
for renyuan in chou_list:
print(renyuan)
print("人员有: ", self.data.iloc[renyuan, 2])
self.getrenshu.append(self.data.iloc[renyuan, 2]+"编号为: "+str(self.data.iloc[renyuan, 1]))
except Exception as e:
self.getrenshu.append("程序出错 ,检查")
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QFileDialogDemo()
main.show()
sys.exit(app.exec_())
原文地址:https://www.jb51.cc/wenti/3284076.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。