抽奖demo

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_())
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值