使用pyqt5制作简单计分桌面应用

news/2024/11/16 15:37:53/文章来源:https://www.cnblogs.com/dongxuelove/p/18296159

这是一个自己写的使用pyqt5制作简单计分桌面应用的实例,希望对大家有所帮助。制作这个小程序的起因是因为有个艺术类比赛需要设计这个一个桌面程序,方便统分。

(此程序尚存在部分小bug,请慎用,公开代码只为让小白熟悉如何开发一个简单的桌面计分程序)

ui设计

众所周知,使用pyqt5开发可以直接使用designer来设计界面,所以,我将页面代码直接贴给大家,具体效果截图展示。

比赛准备阶段界面

image-20240711143434332

比赛进行中界面

image-20240711143507616

完整ui代码

为了方便,并没有转成.py形式的文件

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>Form</class><widget class="QWidget" name="Form"><property name="enabled"><bool>true</bool></property><property name="geometry"><rect><x>0</x><y>0</y><width>1920</width><height>1080</height></rect></property><property name="minimumSize"><size><width>1920</width><height>1080</height></size></property><property name="maximumSize"><size><width>1920</width><height>1080</height></size></property><property name="windowTitle"><string>Form</string></property><widget class="QWidget" name="race_prepare_page" native="true"><property name="enabled"><bool>true</bool></property><property name="geometry"><rect><x>440</x><y>130</y><width>1211</width><height>721</height></rect></property><property name="styleSheet"><string notr="true"/></property><widget class="QTableWidget" name="score_table_display"><property name="enabled"><bool>true</bool></property><property name="geometry"><rect><x>580</x><y>190</y><width>621</width><height>341</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property></widget><widget class="QLabel" name="score_display_label"><property name="geometry"><rect><x>830</x><y>540</y><width>131</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>选手信息展示</string></property></widget><widget class="QPushButton" name="race_info_button"><property name="geometry"><rect><x>200</x><y>660</y><width>121</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>确认信息</string></property></widget><widget class="QPushButton" name="race_start_button"><property name="geometry"><rect><x>740</x><y>90</y><width>121</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>比赛开始</string></property></widget><widget class="QLabel" name="race_preparation_label"><property name="geometry"><rect><x>510</x><y>10</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 30px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>比赛准备阶段</string></property></widget><widget class="QLabel" name="music_name_label"><property name="enabled"><bool>true</bool></property><property name="geometry"><rect><x>10</x><y>350</y><width>91</width><height>81</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>请按选手排序输入曲名名称</string></property><property name="wordWrap"><bool>true</bool></property></widget><widget class="QRadioButton" name="remove_yes"><property name="geometry"><rect><x>250</x><y>560</y><width>61</width><height>21</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>是</string></property></widget><widget class="QLineEdit" name="judge_number_input"><property name="geometry"><rect><x>100</x><y>110</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="race_name_label"><property name="geometry"><rect><x>10</x><y>60</y><width>91</width><height>24</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>比赛名称</string></property></widget><widget class="QTextEdit" name="judge_namelist_input"><property name="geometry"><rect><x>100</x><y>160</y><width>151</width><height>171</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="markdown"><string/></property><property name="html"><string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:20px; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string></property><property name="placeholderText"><string>填写示例:   张三                 李四</string></property></widget><widget class="QLabel" name="judge_number_label"><property name="geometry"><rect><x>11</x><y>116</y><width>81</width><height>24</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>评委数量</string></property></widget><widget class="QTextEdit" name="player_namelist_input"><property name="geometry"><rect><x>390</x><y>160</y><width>151</width><height>171</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="markdown"><string/></property><property name="html"><string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:20px; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string></property><property name="placeholderText"><string>填写示例:   张三               李四</string></property></widget><widget class="QLabel" name="player_name_label"><property name="geometry"><rect><x>300</x><y>160</y><width>91</width><height>81</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>请按选手排序输入姓名</string></property><property name="wordWrap"><bool>true</bool></property></widget><widget class="QLineEdit" name="race_name_input"><property name="geometry"><rect><x>100</x><y>54</y><width>441</width><height>31</height></rect></property><property name="accessibleName"><string/></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="inputMask"><string/></property><property name="text"><string/></property><property name="placeholderText"><string>默认比赛</string></property></widget><widget class="QLabel" name="judge_name_label"><property name="geometry"><rect><x>10</x><y>160</y><width>91</width><height>81</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>请按评委排序输入姓名</string></property><property name="wordWrap"><bool>true</bool></property></widget><widget class="QLineEdit" name="player_number_input"><property name="geometry"><rect><x>390</x><y>110</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QRadioButton" name="remove_no"><property name="geometry"><rect><x>340</x><y>560</y><width>51</width><height>21</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>否</string></property></widget><widget class="QLabel" name="remove_score_label"><property name="geometry"><rect><x>10</x><y>614</y><width>221</width><height>24</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>去掉几个最高分和最低分</string></property></widget><widget class="QLineEdit" name="remove_score_input"><property name="geometry"><rect><x>250</x><y>610</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="player_number_label"><property name="geometry"><rect><x>300</x><y>116</y><width>91</width><height>24</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>选手数量</string></property></widget><widget class="QLabel" name="remove_choose_label"><property name="geometry"><rect><x>10</x><y>560</y><width>221</width><height>24</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>是否去掉最高分和最低分</string></property></widget><widget class="QTextEdit" name="music_namelist_input"><property name="geometry"><rect><x>100</x><y>350</y><width>441</width><height>181</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="markdown"><string/></property><property name="html"><string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:20px; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string></property><property name="placeholderText"><string>填写示例:                                  古典乐                                       爵士乐</string></property></widget><widget class="QPushButton" name="continue_race_button"><property name="geometry"><rect><x>890</x><y>90</y><width>151</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>继续上次比赛</string></property></widget><widget class="QPushButton" name="quit_code_button"><property name="geometry"><rect><x>1070</x><y>90</y><width>121</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>退出程序</string></property></widget><widget class="QPushButton" name="save_info_button"><property name="geometry"><rect><x>590</x><y>90</y><width>121</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>保存信息</string></property></widget></widget><widget class="QWidget" name="race_going_page" native="true"><property name="geometry"><rect><x>440</x><y>130</y><width>1211</width><height>721</height></rect></property><widget class="QLabel" name="race_going_label"><property name="geometry"><rect><x>0</x><y>10</y><width>1211</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 30px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>比赛进行阶段</string></property><property name="alignment"><set>Qt::AlignCenter</set></property></widget><widget class="QLabel" name="judge_one_label_1"><property name="geometry"><rect><x>80</x><y>146</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:1号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_1"><property name="geometry"><rect><x>300</x><y>150</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_one_label_2"><property name="geometry"><rect><x>81</x><y>202</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:2号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_2"><property name="geometry"><rect><x>301</x><y>206</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_one_label_3"><property name="geometry"><rect><x>81</x><y>252</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:3号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_3"><property name="geometry"><rect><x>301</x><y>256</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_4"><property name="geometry"><rect><x>300</x><y>310</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_one_label_4"><property name="geometry"><rect><x>80</x><y>306</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:4号评委</string></property></widget><widget class="QLabel" name="judge_one_label_5"><property name="geometry"><rect><x>81</x><y>362</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:5号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_5"><property name="geometry"><rect><x>301</x><y>366</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_one_label_6"><property name="geometry"><rect><x>81</x><y>422</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:6号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_6"><property name="geometry"><rect><x>301</x><y>426</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_one_label_7"><property name="geometry"><rect><x>81</x><y>482</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:7号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_7"><property name="geometry"><rect><x>301</x><y>486</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_one_label_8"><property name="geometry"><rect><x>81</x><y>542</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:8号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_8"><property name="geometry"><rect><x>301</x><y>546</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_one_label_9"><property name="geometry"><rect><x>81</x><y>602</y><width>181</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 20px;</string></property><property name="text"><string>姓名:9号评委</string></property></widget><widget class="QLineEdit" name="judgeone_score_input_9"><property name="geometry"><rect><x>301</x><y>606</y><width>151</width><height>31</height></rect></property><property name="styleSheet"><string notr="true">font: 20px ;</string></property><property name="text"><string/></property><property name="placeholderText"><string>填写示例:1</string></property></widget><widget class="QLabel" name="judge_com_label_1"><property name="geometry"><rect><x>510</x><y>250</y><width>151</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 24px;</string></property><property name="text"><string>最高分:</string></property></widget><widget class="QLabel" name="judge_com_label_2"><property name="geometry"><rect><x>700</x><y>250</y><width>161</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 24px;</string></property><property name="text"><string>最低分:</string></property></widget><widget class="QLabel" name="judge_com_label_3"><property name="geometry"><rect><x>510</x><y>320</y><width>151</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 30px;</string></property><property name="text"><string>实际得分:</string></property></widget><widget class="QLabel" name="judge_com_label_4"><property name="geometry"><rect><x>670</x><y>300</y><width>181</width><height>81</height></rect></property><property name="styleSheet"><string notr="true">font: 60px;</string></property><property name="text"><string/></property></widget><widget class="QPushButton" name="next_player_button"><property name="geometry"><rect><x>630</x><y>170</y><width>151</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>下一个选手</string></property></widget><widget class="QPushButton" name="exit_race_button"><property name="geometry"><rect><x>970</x><y>170</y><width>151</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>比赛结束</string></property></widget><widget class="QLabel" name="current_player_label"><property name="geometry"><rect><x>80</x><y>90</y><width>1091</width><height>41</height></rect></property><property name="styleSheet"><string notr="true">font: 24px;</string></property><property name="text"><string>当前选手:</string></property></widget><widget class="QPushButton" name="player_quit_button"><property name="geometry"><rect><x>800</x><y>170</y><width>151</width><height>51</height></rect></property><property name="styleSheet"><string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string></property><property name="text"><string>当前选手弃权</string></property></widget></widget></widget><resources/><connections/>
</ui>

代码设计

程序主要功能包含,文件上传,文件读取,分数计算,然后还有一些按钮绑定事件。

from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import uicimport keyboard
import sys
import os
import pandas as pd
import docxdef get_path(relative_path):try:base_path = sys._MEIPASSexcept AttributeError:base_path = os.path.abspath(".")return os.path.normpath(os.path.join(base_path, relative_path))def get_decimal_places(num):import decimalif '.' in str(num):num = str(float(num))   #如果传入的是字符串形式的浮点数,先去掉小数后面无意义的0d = decimal.Decimal(str(num))return abs(d.as_tuple().exponent)def del_files(path_file):ls = os.listdir(path_file)for i in ls:f_path = os.path.join(path_file, i)# 判断是否是一个目录,若是,则递归删除if os.path.isdir(f_path):del_files(f_path)else:os.remove(f_path)class MyWindow(QWidget):def __init__(self):super().__init__()self.ui = uic.loadUi(get_path("assets/comscore_final.ui")) #读取ui文件# 展示窗口self.ui.setWindowTitle('比赛计分系统')self.ui.setWindowFlag(Qt.WindowCloseButtonHint, False)#提取每个要使用的控件 #比赛准备阶段  self.race_prepare=self.ui.race_prepare_page #比赛准备页面self.race_name=self.ui.race_name_input #比赛名称self.judge_number=self.ui.judge_number_input #评委数量self.judge_namelist=self.ui.judge_namelist_input #评委信息self.player_number=self.ui.player_number_input #选手数量self.player_namelist=self.ui.player_namelist_input #选手信息self.music_namelist=self.ui.music_namelist_input #音乐信息self.race_info=self.ui.race_info_button #确认信息按钮self.continue_race=self.ui.continue_race_button #继续上次比赛按钮self.race_start=self.ui.race_start_button #比赛开始按钮'self.remove_score=self.ui.remove_score_input self.save_info=self.ui.save_info_button #保存信息self.quit_code=self.ui.quit_code_button #退出程序self.race_start.setEnabled(False)self.save_info.setEnabled(False)#是否去掉最高分和最低分self.remove_yes_radiobox=self.ui.remove_yesself.remove_no_radiobox=self.ui.remove_no#去掉最高分和最低分的数量self.remove_score_label_now=self.ui.remove_score_labelself.remove_score=self.ui.remove_score_input #默认选择不去掉,并且设置不显示去掉几个最高分和最低分的框self.remove_no_radiobox.setChecked(True)self.remove_score.setVisible(False) #初始设置隐藏self.remove_score_label_now.setVisible(False) #初始设置隐藏#toggled信号与槽函数绑定self.remove_yes_radiobox.toggled.connect(lambda :self.func_radiobox_btnstate(self.remove_yes_radiobox))self.remove_no_radiobox.toggled.connect(lambda :self.func_radiobox_btnstate(self.remove_no_radiobox))#选手信息展示self.score_table=self.ui.score_table_display #选手信息展示# 绑定信号与槽函数self.race_info.clicked.connect(self.func_race_info) #信息导入self.continue_race.clicked.connect(self.func_continue_race)# 根据文件来读取信息self.race_start.clicked.connect(self.func_race_start) #比赛开始按钮self.save_info.clicked.connect(self.func_save_info) #保存信息self.quit_code.clicked.connect(self.func_quit_code)#选手信息展示区域函数self.score_table.setSelectionMode(QAbstractItemView.SingleSelection)#设置选取方式为单个选取self.score_table.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) #设置水平滚动self.score_table.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)  #设置竖直滚动#---------------------------------------------------------------------------------------------------------------------#---------------------------------------------------------------------------------------------------------------------#比赛进行阶段self.race_going=self.ui.race_going_page #比赛进行页面self.race_going.setVisible(False) #初始设置隐藏self.race_going_name=self.ui.race_going_label#当前选手self.current_player=self.ui.current_player_label #评委列表self.judge_one_1=self.ui.judge_one_label_1self.judgeone_score_1=self.ui.judgeone_score_input_1#设置校验规则,实例化浮点校验器,并设置范围0~10,精度为小数点两位myValidator = QRegExpValidator(QRegExp("^(10|\d(\.\d{1,2})?)$"))#初始设置隐藏for show_i in range(1,10):judge_one_label_name="judge_one_label_"+str(show_i)judge_one_temp = self.race_going.findChild(QLabel,judge_one_label_name)judge_one_temp.setVisible(False)judgeone_score_input_name="judgeone_score_input_"+str(show_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.setVisible(False)#设置校验规则,限制只能输入数字还有小数后两位judgeone_score_temp.returnPressed.connect(self.func_text_change)judgeone_score_temp.setValidator(myValidator)#最高分,最低分,实际得分self.judge_com_max=self.ui.judge_com_label_1  #最高分self.judge_com_min=self.ui.judge_com_label_2  #最低分self.judge_com_average_label=self.ui.judge_com_label_3  #实际得分标签self.judge_com_average=self.ui.judge_com_label_4 #分数for show_i in range(1,5):judge_com_label_name="judge_com_label_"+str(show_i)judge_com_temp = self.race_going.findChild(QLabel,judge_com_label_name)judge_com_temp.setVisible(False)#计算总分按钮# self.com_score=self.ui.com_score_button #下一个选手按钮self.next_player=self.ui.next_player_button #比赛结束按钮self.exit_race=self.ui.exit_race_button #选手弃权按钮self.player_quit=self.ui.player_quit_button# 绑定信号与槽函数# self.com_score.clicked.connect(self.func_com_score) #计算总分self.next_player.clicked.connect(self.func_next_player) #下一个选手self.exit_race.clicked.connect(self.func_exit_race) #结束比赛self.player_quit.clicked.connect(self.func_player_quit) #选手弃权#赋予一个全局使用的数据变量self.all_data_df=[]self.have_score_number=0 #表示当前已经计分的选手数量self.remove_score_number=0def func_save_info(self):reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否保存信息?',QMessageBox.Question)if reply_one == QMessageBox.Yes: #先将读取的数据保存起来,以tablewight数据表信息为准player_index=[]player_name=[]music_name=[]for qtable_row in range(int(self.player_number.text())):player_index.append(self.score_table.item(qtable_row,0).text())  #获取某行某列item中的x信息player_name.append(self.score_table.item(qtable_row,1).text())  #获取某行某列item中的x信息music_name.append(self.score_table.item(qtable_row,2).text())  #获取某行某列item中的x信息judge_all_list=[]for qtable_column in range(int(self.judge_number.text())):judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格judge_all_list.append(judge_one_list)# creating the DataFrameall_data = pd.DataFrame(list(zip(player_index, player_name, music_name))) all_data.columns =['抽签序号', '选手姓名', '曲目名称'] #设置列名judge_namelist_temp=self.judge_namelist.toPlainText().split('\n')for qtable_column in range(int(self.judge_number.text())):judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格judge_column_name=judge_namelist_temp[qtable_column]+":"+str(qtable_column+1)+"号评委"all_data[judge_column_name]=judge_one_list#增加最高分,最低分列 ,增加实际得分列if self.remove_yes_radiobox.isChecked()==True:max_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最高分']=max_one_listmin_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最低分']=min_one_listvisual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格all_data['实得分']=visual_one_listindex_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最终排名']=index_one_listremove_score_str=self.remove_score.text()self.remove_score_number=int(self.remove_score.text())remove_one_list=[remove_score_str]*int(self.player_number.text()) #将列数据全部填充为空格all_data['去掉几个最高分']=remove_one_listelse:visual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格all_data['实得分']=visual_one_listindex_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最终排名']=index_one_listremove_one_list=['0']*int(self.player_number.text()) #将列数据全部填充为空格all_data['去掉几个最高分']=remove_one_listall_data['抽签序号']=all_data['抽签序号'].astype(int)all_data=all_data.sort_values(by=['抽签序号']) #按照抽签序号排序all_data=all_data.reset_index(drop=True) #重新排列一下索引all_data.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引#恢复所有数据初始状态self.all_data_df=[]self.have_score_number=0 #表示当前已经计分的选手数量self.remove_score_number=0#默认选择不去掉,并且设置不显示去掉几个最高分和最低分的框self.remove_no_radiobox.setChecked(True)self.remove_score.setVisible(False) #初始设置隐藏self.remove_score_label_now.setVisible(False) #初始设置隐藏#然后要清空所有的输入self.race_name.setText("") #比赛名称self.judge_number.setText("") #评委数量self.judge_namelist.setText("") #评委信息self.player_number.setText("") #选手数量self.player_namelist.setText("") #选手信息self.music_namelist.setText("") #音乐信息#然后清空qtablewightself.score_table.setRowCount(0)self.score_table.setColumnCount(0)self.score_table.clearContents()#设置按钮不可用self.race_start.setEnabled(False)self.save_info.setEnabled(False)self.setQMessageBoxoneButtonTextENToCN("提示","保存信息成功",QMessageBox.Information)returnelse:self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)returnreturnreturndef func_quit_code(self):reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否退出程序?',QMessageBox.Question)if reply_one == QMessageBox.Yes: self.setQMessageBoxoneButtonTextENToCN("提示","退出程序成功",QMessageBox.Information)sys.exit(0)returnelse:self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)returnreturndef func_text_change(self):#在输入框内按下enter,就会进入这里#获取数据,保存这个选手的得分到临时表格中all_data_temp=self.all_data_dfjudge_number=0if int(all_data_temp.loc[0,'去掉几个最高分'])>0:judge_number=int(all_data_temp.shape[1])-8else:judge_number=int(all_data_temp.shape[1])-6#遍历所有输入框,然后找到第一个为空的输入框,设置它为setFocus即可for com_i in range(1,judge_number+1):judgeone_score_input_name="judgeone_score_input_"+str(com_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)if judgeone_score_temp.text()=='':judgeone_score_temp.setFocus()returnelse:continue#获取数据,保存这个选手的得分到临时表格中all_data_temp=self.all_data_dfprint(self.all_data_df)reply_zero=self.setQMessageBoxtwoButtonTextENToCN('提示', '评委得分是否输入正确?',QMessageBox.Question)if reply_zero == QMessageBox.Yes:#根据评委数量来获取输入框数据score_list_temp=[]save_score_list=[]judge_number=0if int(all_data_temp.loc[0,'去掉几个最高分'])>0:judge_number=int(all_data_temp.shape[1])-8else:judge_number=int(all_data_temp.shape[1])-6print(judge_number)for com_i in range(1,judge_number+1):judgeone_score_input_name="judgeone_score_input_"+str(com_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.setReadOnly(True)  #设置为只读if judgeone_score_temp.text()=='':self.setQMessageBoxoneButtonTextENToCN("提示",str(com_i)+"评委分数未填写",QMessageBox.Information)returnelse:score_list_temp.append(float(judgeone_score_temp.text()))save_score_list.append(float(judgeone_score_temp.text()))print(score_list_temp)score_list_temp.sort() #对打分进行排序#设置最高分score_list_temp_max=max(score_list_temp)self.judge_com_max.setText("最高分: "+str(score_list_temp_max))# self.score_table.setText(score_list_temp_max)#设置最低分score_list_temp_min=min(score_list_temp)self.judge_com_min.setText("最低分: "+str(score_list_temp_min))for flag in range(self.remove_score_number):score_list_temp.pop() #删除最后一项score_list_temp.pop(0) #删除第一项#设置最终分数average_score=round(sum(score_list_temp)/len(score_list_temp),3)#设置self.judge_com_average.setText(str(average_score))#确定当前计算的是哪个选手,至少有一个评委current_player_row=0player_row=int(all_data_temp.shape[0])for player_row_index in range(0,player_row):print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')if str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1' or str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1.0':current_player_row=player_row_indexbreakcurrent_player_row=player_row_indexself.have_score_number=current_player_row#保存方法在有最高分和没有最高分时有所不同,有if int(all_data_temp.loc[0,'去掉几个最高分'])>0:#将这里面的数据进行覆盖  操作的是save_score_list,score_list_temp_max,score_list_temp_minprint(save_score_list)for judge_number_index in range(0,judge_number):print(judge_number_index)all_data_temp.iloc[current_player_row,judge_number_index+3]=save_score_list[judge_number_index]   all_data_temp.iloc[current_player_row,judge_number_index+4]=score_list_temp_max all_data_temp.iloc[current_player_row,judge_number_index+5]=score_list_temp_minall_data_temp.iloc[current_player_row,judge_number_index+6]=average_scoreelse:for judge_number_index in range(0,judge_number):all_data_temp.iloc[current_player_row,judge_number_index+3]=save_score_list[judge_number_index]   all_data_temp.iloc[current_player_row,judge_number_index+4]=average_score#重新保存数据表,最后再赋值回去all_data_temp.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引self.all_data_df=all_data_tempprint(self.all_data_df)# #清空分数框         # for show_i in range(1,judge_number+1):#     judgeone_score_input_name="judgeone_score_input_"+str(show_i)#     judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)#     judgeone_score_temp.clear()self.have_score_number=self.have_score_number+1 #保存当前选手序号,只用于验证选手是否弃权print("self.have_score_number=",self.have_score_number)returnelse:self.setQMessageBoxoneButtonTextENToCN("提示","请检查后,继续填写",QMessageBox.Information)returnreturn#单选按钮绑定def func_radiobox_btnstate(self,btn):#输出按钮1与按钮2的状态,选中还是没选中if btn.text()=='是':if btn.isChecked()==True:# print(btn.text()+"is selected")self.remove_score.setVisible(True) #初始设置隐藏self.remove_score_label_now.setVisible(True) #初始设置隐藏else:# print(btn.text()+"is deselected")returnif btn.text()=="否":if btn.isChecked() == True:# print(btn.text() + "is selected")self.remove_score.setVisible(False) #初始设置隐藏self.remove_score_label_now.setVisible(False) #初始设置隐藏self.remove_score.setText("") #重新设置为空else:# print(btn.text() + "is deselected")returndef setQMessageBoxtwoButtonTextENToCN(self,windowTitle, text,  qmessageIcon):"""设置需要的QMessageBox的按钮提示为中文:param qmessageIcon: 显示图标  例如QMessageBox.Question:param kwargs: 确定=QMessageBox.AcceptRole"""msgBox = QMessageBox()msgBox.setWindowTitle(windowTitle)msgBox.setText(text)msgBox.setIcon(qmessageIcon)msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)buttonY = msgBox.button(QMessageBox.Yes)buttonY.setText('是')buttonN = msgBox.button(QMessageBox.No)buttonN.setText('否')ret=msgBox.exec_()return retdef setQMessageappENToCN(self,windowTitle, text,  qmessageIcon):"""设置需要的QMessageBox的按钮提示为中文:param qmessageIcon: 显示图标  例如QMessageBox.Question:param kwargs: 确定=QMessageBox.AcceptRole"""msgBox = QMessageBox()msgBox.setWindowTitle(windowTitle)msgBox.setText(text)msgBox.setIcon(qmessageIcon)msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)buttonY = msgBox.button(QMessageBox.Yes)buttonY.setText('比赛暂停')buttonN = msgBox.button(QMessageBox.No)buttonN.setText('比赛结束')ret=msgBox.exec_()return retdef setQMessageBoxoneButtonTextENToCN(self,windowTitle, text,  qmessageIcon):"""设置需要的QMessageBox的按钮提示为中文:param qmessageIcon: 显示图标  例如QMessageBox.Question:param kwargs: 确定=QMessageBox.AcceptRole"""msgBox = QMessageBox()msgBox.setWindowTitle(windowTitle)msgBox.setText(text)msgBox.setIcon(qmessageIcon)msgBox.setStandardButtons(QMessageBox.Yes)buttonY = msgBox.button(QMessageBox.Yes)buttonY.setText('是')msgBox.exec_()#根据输入框来读取信息已经无误def func_race_info(self):reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否确认比赛准备信息无误?',QMessageBox.Question)if reply_one == QMessageBox.No:    self.setQMessageBoxoneButtonTextENToCN("提示","请继续填写",QMessageBox.Information)return#检查是否有未填写数据if self.race_name.text()=='' or self.judge_number.text()=='' or self.judge_namelist.toPlainText()=='' or self.player_number.text()==''  or self.player_namelist.toPlainText()=='' or self.music_namelist.toPlainText()=='':self.setQMessageBoxoneButtonTextENToCN("提示","有未填写数据",QMessageBox.Information)returnif self.remove_score.text()=='' and self.remove_yes_radiobox.isChecked()==True:self.setQMessageBoxoneButtonTextENToCN("提示","有未填写数据",QMessageBox.Information)return#检查评委数量是否足够if  int(self.judge_number.text())!=len(self.judge_namelist.toPlainText().split('\n')):self.setQMessageBoxoneButtonTextENToCN("提示","评委数量与评委姓名数量不对应,请重新填写",QMessageBox.Information)return#检查选手数量是否足够if  int(self.player_number.text())!=len(self.player_namelist.toPlainText().split('\n')):self.setQMessageBoxoneButtonTextENToCN("提示","选手数量与选手姓名数量不对应,请重新填写",QMessageBox.Information)return#检查曲目数量是否足够if  int(self.player_number.text())!=len(self.music_namelist.toPlainText().split('\n')):self.setQMessageBoxoneButtonTextENToCN("提示","音乐数量与选手数量不对应,请重新填写",QMessageBox.Information)returnif reply_one == QMessageBox.Yes:    self.setQMessageBoxoneButtonTextENToCN("提示","比赛准备信息填写成功",QMessageBox.Information)          self.score_table.setColumnCount(3)self.score_table.setRowCount(int(self.player_number.text()))column_namelist_temp=["抽签序号","选手姓名","曲目名称"]self.score_table.setHorizontalHeaderLabels(column_namelist_temp) #设置行表头player_namelist_temp=self.player_namelist.toPlainText().split('\n')music_namelist_temp=self.music_namelist.toPlainText().split('\n')for i in range(int(self.player_number.text())):self.score_table.setItem(i,0, QTableWidgetItem(str(i+1)))self.score_table.setItem(i,1, QTableWidgetItem(player_namelist_temp[i]))self.score_table.setItem(i,2, QTableWidgetItem(music_namelist_temp[i]))#设置按钮可用self.race_start.setEnabled(True)self.save_info.setEnabled(True)#给设置自适应宽度self.score_table.resizeColumnToContents(0)self.score_table.resizeColumnToContents(1)self.score_table.resizeColumnToContents(2)returnreturn#这是按照全新比赛的操作def func_race_start(self):#先将读取的数据保存起来,以tablewight数据表信息为准player_index=[]player_name=[]music_name=[]for qtable_row in range(int(self.player_number.text())):player_index.append(self.score_table.item(qtable_row,0).text())  #获取某行某列item中的x信息player_name.append(self.score_table.item(qtable_row,1).text())  #获取某行某列item中的x信息music_name.append(self.score_table.item(qtable_row,2).text())  #获取某行某列item中的x信息judge_all_list=[]for qtable_column in range(int(self.judge_number.text())):judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格judge_all_list.append(judge_one_list)# creating the DataFrameall_data = pd.DataFrame(list(zip(player_index, player_name, music_name))) all_data.columns =['抽签序号', '选手姓名', '曲目名称'] #设置列名judge_namelist_temp=self.judge_namelist.toPlainText().split('\n')for qtable_column in range(int(self.judge_number.text())):judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格judge_column_name=judge_namelist_temp[qtable_column]+":"+str(qtable_column+1)+"号评委"all_data[judge_column_name]=judge_one_list#增加最高分,最低分列 ,增加实际得分列if self.remove_yes_radiobox.isChecked()==True:max_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最高分']=max_one_listmin_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最低分']=min_one_listvisual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格all_data['实得分']=visual_one_listindex_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最终排名']=index_one_listremove_score_str=self.remove_score.text()self.remove_score_number=int(self.remove_score.text())remove_one_list=[remove_score_str]*int(self.player_number.text()) #将列数据全部填充为空格all_data['去掉几个最高分']=remove_one_listelse:visual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格all_data['实得分']=visual_one_listindex_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格all_data['最终排名']=index_one_listremove_one_list=['0']*int(self.player_number.text()) #将列数据全部填充为空格all_data['去掉几个最高分']=remove_one_listall_data['抽签序号']=all_data['抽签序号'].astype(int)all_data=all_data.sort_values(by=['抽签序号']) #按照抽签序号排序all_data=all_data.reset_index(drop=True) #重新排列一下索引all_data.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引self.all_data_df=all_data#界面展示与隐藏self.race_prepare.setVisible(False) #初始设置隐藏self.race_going.setVisible(True) #初始设置隐藏#设置比赛名称self.race_going_name.setText(self.race_name.text())# 展示当前选手信息,需要读取数据表的1号来展示self.current_player.setText("当前选手:1号选手"+str(all_data.loc[0,'选手姓名']))#根据评委数量来显示评委框judge_number=int(self.judge_number.text())judge_one_namelist=self.judge_namelist.toPlainText().split('\n')for show_i in range(1,judge_number+1):judge_one_label_name="judge_one_label_"+str(show_i)judge_one_temp = self.race_going.findChild(QLabel,judge_one_label_name)#设置评委label的textjudge_one_temp.setText(judge_one_namelist[show_i-1]+":"+str(show_i)+"号评委")judge_one_temp.setVisible(True)judgeone_score_input_name="judgeone_score_input_"+str(show_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.setVisible(True)#根据是否需要去掉最高分和最低分来展示if self.remove_yes_radiobox.isChecked()==True:#去掉了最高分和最低分,那么就显示所有的for show_i in range(1,5):judge_com_label_name="judge_com_label_"+str(show_i)judge_com_temp = self.race_going.findChild(QLabel,judge_com_label_name)judge_com_temp.setVisible(True)else:#不去掉,则只显示,实际得分self.judge_com_average_label.setVisible(True)self.judge_com_average.setVisible(True)return#下一个选手def func_next_player(self):#获取数据,保存这个选手的得分到临时表格中all_data_temp=self.all_data_dfprint(self.all_data_df)#先询问是否计算最终得分,获取输入框信息,计算得分,然后展示出来,展示出来之后将信息保存到临时数据表中reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否跳到下一个选手?',QMessageBox.Question)if reply_one == QMessageBox.Yes:    #先判断选手是否是弃权#确定当前计算的是哪个选手,至少有一个评委current_player_row=0#找到第一个未计分的选手player_row=int(all_data_temp.shape[0])print("player_row=",player_row)for player_row_index in range(0,player_row):print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')if str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1' or str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1.0':current_player_row=player_row_indexbreakcurrent_player_row=player_row_indexself.have_score_number=current_player_row+1print("current_player_row=",current_player_row)print("player_row=",player_row)print("self.have_score_number=",self.have_score_number)if self.have_score_number==player_row:#这时候比赛就提示已经统计完所有选手分数self.setQMessageBoxoneButtonTextENToCN("提示","已统计完所有选手分数",QMessageBox.Information)  self.current_player.setText("本场比赛所有选手已比赛完毕,请退出程序")#保存方法在有最高分和没有最高分时有所不同,有judge_number=0if int(all_data_temp.loc[0,'去掉几个最高分'])>0:judge_number=int(all_data_temp.shape[1])-8else:judge_number=int(all_data_temp.shape[1])-6#清空分数框for show_i in range(1,judge_number+1):judgeone_score_input_name="judgeone_score_input_"+str(show_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.clear()# judgeone_score_temp.setReadOnly(False)  #恢复成可修改if int(all_data_temp.loc[0,'去掉几个最高分'])>0:#设置最高分self.judge_com_max.setText("最高分: ")#设置最低分self.judge_com_min.setText("最低分: ")#设置最终分数self.judge_com_average.setText(str(''))else:#设置最终分数self.judge_com_average.setText(str(''))self.judgeone_score_1.setFocus() #设置光标#设置按钮不可点击self.next_player.setEnabled(False)#选手弃权按钮self.player_quit.setEnabled(False)returnelse:judge_number=0if int(all_data_temp.loc[0,'去掉几个最高分'])>0:judge_number=int(all_data_temp.shape[1])-8else:judge_number=int(all_data_temp.shape[1])-6#current_player_row表示当前第一个空的数据选手序号,self.have_score_number表示已经填写的选手数据序号,# 如果不一样,说明这个选手弃权了,需要把所有数据填写完毕# 如果计算数据表里的和当前的一样,那就说明没有弃权print("self.have_score_number=",self.have_score_number)print("current_player_row=",current_player_row)#正常切换,只需要重新设置一些信息即可#清空分数框for show_i in range(1,judge_number+1):judgeone_score_input_name="judgeone_score_input_"+str(show_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.clear()judgeone_score_temp.setReadOnly(False)  #恢复成可修改if int(all_data_temp.loc[0,'去掉几个最高分'])>0:#重新设置文字信息#设置下一个选手self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")#设置最高分self.judge_com_max.setText("最高分: ")#设置最低分self.judge_com_min.setText("最低分: ")#设置最终分数self.judge_com_average.setText(str(''))else:#设置下一个选手self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")#设置最终分数self.judge_com_average.setText(str(''))self.judgeone_score_1.setFocus() #设置光标returnreturnelse:self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)returnreturndef func_player_quit(self):#获取数据,保存这个选手的得分到临时表格中all_data_temp=self.all_data_dfprint(self.all_data_df)current_player_row=0#先询问是否计算最终得分,获取输入框信息,计算得分,然后展示出来,展示出来之后将信息保存到临时数据表中reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '当前选手是否弃权?',QMessageBox.Question)if reply_one == QMessageBox.Yes:    #选手弃权judge_number=0if int(all_data_temp.loc[0,'去掉几个最高分'])>0:judge_number=int(all_data_temp.shape[1])-8else:judge_number=int(all_data_temp.shape[1])-6#清空分数框for show_i in range(1,judge_number+1):judgeone_score_input_name="judgeone_score_input_"+str(show_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.clear()#找到第一个未计分的选手player_row=int(all_data_temp.shape[0])print("player_row=",player_row)for player_row_index in range(0,player_row):print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')if str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1' or str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1.0':current_player_row=player_row_indexbreakcurrent_player_row=player_row_indexself.have_score_number=current_player_rowif self.have_score_number==player_row:#这时候比赛就提示已经统计完所有选手分数self.setQMessageBoxoneButtonTextENToCN("提示","已统计完所有选手分数",QMessageBox.Information)#设置按钮不可点击self.next_player.setEnabled(False)#选手弃权按钮self.player_quit.setEnabled(False)returnelse:#保存方法在有最高分和没有最高分时有所不同,有if int(all_data_temp.loc[0,'去掉几个最高分'])>0:#将这里面的数据进行覆盖  操作的是save_score_list,score_list_temp_max,score_list_temp_minfor judge_number_index in range(0,judge_number):print(judge_number_index)all_data_temp.iloc[current_player_row,judge_number_index+3]=0  all_data_temp.iloc[current_player_row,judge_number_index+4]=0 all_data_temp.iloc[current_player_row,judge_number_index+5]=0all_data_temp.iloc[current_player_row,judge_number_index+6]=0else:for judge_number_index in range(0,judge_number):all_data_temp.iloc[current_player_row,judge_number_index+3]=0   all_data_temp.iloc[current_player_row,judge_number_index+4]=0print("弃权后all_data_temp=",all_data_temp)#重新保存数据表,最后再赋值回去all_data_temp.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引self.all_data_df=all_data_tempself.have_score_number=self.have_score_number+1self.setQMessageBoxoneButtonTextENToCN("提示",str(current_player_row+1)+"号选手"+str(all_data_temp.loc[current_player_row,'选手姓名'])+"弃权成功,马上跳到下一个选手",QMessageBox.Information)if self.have_score_number==player_row:#这时候比赛就提示已经统计完所有选手分数self.setQMessageBoxoneButtonTextENToCN("提示","已统计完所有选手分数",QMessageBox.Information)self.current_player.setText("本场比赛所有选手已比赛完毕,请退出程序")#保存方法在有最高分和没有最高分时有所不同,有#清空分数框for show_i in range(1,judge_number+1):judgeone_score_input_name="judgeone_score_input_"+str(show_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.clear()if int(all_data_temp.loc[0,'去掉几个最高分'])>0:#设置最高分self.judge_com_max.setText("最高分: ")#设置最低分self.judge_com_min.setText("最低分: ")#设置最终分数self.judge_com_average.setText(str(''))else:#设置最终分数self.judge_com_average.setText(str(''))self.judgeone_score_1.setFocus() #设置光标#设置按钮不可点击self.next_player.setEnabled(False)#选手弃权按钮self.player_quit.setEnabled(False)returnelse:#跳转到下一个选手if int(all_data_temp.loc[0,'去掉几个最高分'])>0:self.current_player.setText("当前选手:"+str(current_player_row+2)+"号选手"+str(all_data_temp.loc[current_player_row+1,'选手姓名']))#设置最高分self.judge_com_max.setText("最高分: ")#设置最低分self.judge_com_min.setText("最低分: ")#设置最终分数self.judge_com_average.setText(str(''))else:#设置下一个选手self.current_player.setText("当前选手:"+str(current_player_row+2)+"号选手"+str(all_data_temp.loc[current_player_row+1,'选手姓名']))#设置最终分数self.judge_com_average.setText(str(''))self.judgeone_score_1.setFocus() #设置光标returnelse:self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)return#结束比赛def func_exit_race(self):#获取数据,保存这个选手的得分到临时表格中all_data_temp=self.all_data_dfprint(self.all_data_df)reply_zero=self.setQMessageappENToCN('提示', '请选择退出程序的原因?',QMessageBox.Question)if reply_zero == QMessageBox.Yes:reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否确认选择比赛暂停?',QMessageBox.Question)if reply_one == QMessageBox.Yes: self.setQMessageBoxoneButtonTextENToCN("提示","比赛暂停,临时数据保存成功",QMessageBox.Information)sys.exit(0)returnelse:self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)returnreturnelse:reply_two=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否确认选择比赛结束?',QMessageBox.Question)if reply_two == QMessageBox.Yes: #导出数据,清空临时表all_data_temp=all_data_temp.sort_values(by=['实得分'],ascending=False) #按照抽签序号排序all_data_temp=all_data_temp.reset_index(drop=True) #重新排列一下索引player_row=int(all_data_temp.shape[0])print("player_row=",player_row)for player_row_index in range(0,player_row):all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-2]=player_row_index+1all_data_temp.to_excel('save_data/'+str(self.race_name.text())+'_最终数据全部备份版.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引#保留特定数据all_data_temp_new = all_data_temp[['抽签序号', '选手姓名', '曲目名称','实得分','最终排名']]# 创建一个新的文档doc_part=docx.Document()# 添加标题para_heading=doc_part.add_heading(str(self.race_name.text()), 5)para_heading.alignment=docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER#设置为左对齐# 添加表格table_part = doc_part.add_table(rows=all_data_temp_new.shape[0]+1, cols=all_data_temp_new.shape[1])# 添加表头hdr_cells = table_part.rows[0].cellsfor i in range(all_data_temp_new.shape[1]):hdr_cells[i].text = all_data_temp_new.columns[i]# 添加每一行数据for i in range(all_data_temp_new.shape[0]):row_cells = table_part.rows[i+1].cellsfor j in range(all_data_temp_new.shape[1]):row_cells[j].text = str(all_data_temp_new.values[i,j])# 保存文件doc_part.save('save_data/'+str(self.race_name.text())+'_最终数据简洁版.docx')# del_files("temp_data/")self.setQMessageBoxoneButtonTextENToCN("提示","最终数据导出成功,本次比赛临时数据已清除",QMessageBox.Information)sys.exit(0)returnelse:self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)returnreturnreturn#根据文件来读取信息,这个是不一样的,最后写才对,这个继续前次比赛,比赛的信息设置与全新比赛不相同def func_continue_race(self):#先是询问是否继续上次比赛reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否继续上次比赛?',QMessageBox.Question)if reply_one == QMessageBox.Yes:        folderName, _ = QFileDialog.getOpenFileName(self, "选择xlsx文件", "", "*.xlsx")        race_name=folderName.split("/")[-1].split("_")[0]self.race_name.setText(race_name)self.all_data_df=pd.read_excel('temp_data/'+folderName.split("/")[-1],index_col=0)all_data_temp=self.all_data_df#界面展示与隐藏self.race_prepare.setVisible(False) #初始设置隐藏self.race_going.setVisible(True) #初始设置隐藏#设置比赛名称self.race_going_name.setText(race_name)#设置选手初值current_player_row=0#找到第一个未计分的选手player_row=int(all_data_temp.shape[0])print("player_row=",player_row)for player_row_index in range(0,player_row):print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')if str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1' or str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1.0':current_player_row=player_row_indexbreakcurrent_player_row=player_row_indexself.have_score_number=current_player_rowjudge_number=0self.remove_score_number=int(all_data_temp.loc[0,'去掉几个最高分'])#设置界面信息:当前选手,是否展示实得分最高分,评委名字if int(all_data_temp.loc[0,'去掉几个最高分'])>0:self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")for show_i in range(1,5):judge_com_label_name="judge_com_label_"+str(show_i)judge_com_temp = self.race_going.findChild(QLabel,judge_com_label_name)judge_com_temp.setVisible(True)#设置最高分self.judge_com_max.setText("最高分: ")#设置最低分self.judge_com_min.setText("最低分: ")#设置最终分数self.judge_com_average.setText(str(''))judge_number=int(all_data_temp.shape[1])-8else:#设置下一个选手self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")self.judge_com_average_label.setVisible(True)self.judge_com_average.setVisible(True)#设置最终分数self.judge_com_average.setText(str(''))judge_number=int(all_data_temp.shape[1])-6judge_namelist=[column for column in all_data_temp]judge_one_namelist=judge_namelist[3:3+judge_number]for show_i in range(1,judge_number+1):judge_one_label_name="judge_one_label_"+str(show_i)judge_one_temp = self.race_going.findChild(QLabel,judge_one_label_name)#设置评委label的textjudge_one_temp.setText(judge_one_namelist[show_i-1].split(":")[0]+":"+str(show_i)+"号评委")judge_one_temp.setVisible(True)judgeone_score_input_name="judgeone_score_input_"+str(show_i)judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)judgeone_score_temp.setVisible(True)else:self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)returnif __name__ == '__main__':app=QApplication(sys.argv)  w = MyWindow()w.ui.show()app.exec()

程序打包成exe

指令 安装pyinstall库

文件目录
根路径getscore.pyassetsxxx.uisave_datatemp_datapyinstaller -F -w getscore.py --add-data ".\\assets\\*;.\\assets"

参考文章

感谢以下作者的知识分享

PyQt入门教程 - 随笔分类 - 锅边糊 - 博客园 (cnblogs.com)

【创作不易,望点赞收藏,若有疑问,请留言,谢谢】

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/742228.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux-Cgroup V2 初体验

本文主要记录 Linux Cgroup V2 版本基本使用操作,包括 cpu、memory 子系统演示。1. 开启 Cgroup V2 版本检查 通过下面这条命令来查看当前系统使用的 Cgroups V1 还是 V2 stat -fc %T /sys/fs/cgroup/如果输出是cgroup2fs 那就是 V2,就像这样 root@tezn:~# stat -fc %T /sys/…

Linux系统基础学习

系统目录结构 登录系统之后输入ls命令查看系统目录系统常用的目录/bin 存放着最常用的命令,包括用户和系统管理员都会使用的命令。 /boot 存放启动linux的核心文件,包括内核文件、引导文件、镜像文件 /dev 存放着 Linux 系统中所有的设备文件,如硬盘、CD-ROM等 /home 用户的…

《穷查理思维模型实战课程——一个月一场》

好久好久没更新了。穷查理思维模型实战课程——一个月一场 查理芒格的去世,让了当今没有孔子在世。但是他的智慧会让我们继续前行。

.Net Windows Forms(窗体程序)在服务端运行不了的问题

.Net Windows Forms(窗体程序)在服务端运行不了的问题(本机可以) 原因:是在Form1的构造函数中多了这几行,在服务端找不到配制文件。//DomSqlMapBuilder builder = new DomSqlMapBuilder();//ISqlMapper mapper = builder.Configure(@"..\..\App_Data\SqlMap.config…

基于业财一体化和数据集成的费用协同管理系统-虎珀

某药企,作为高新技术企业、也是中国医药工业百强。其业务集药物研发、生产、销售、商业批发和国际营销为一体,为进一步提升集团内部费用管理的精细化与标准化水平,该企业决定引入先进的信息化费用核算系统,将其作为集团费用管理体系中的重要组成部分。 此系统要能够适应不同…

ABC361

A link先输出前\(k\)个,再输出\(x\),最后输出后面的。点击查看代码 #include<bits/stdc++.h>using namespace std;int n,k,x;signed main(){cin >> n >> k >> x;for(int i = 1;i <= n;++ i){int a;cin >> a;cout << a << "…

ali - Kubernetes镜像源

1. Kubernetes镜像源配置 由于 Kubernetes 官方变更了仓库的存储路径以及使用方式,如果需要使用1.28 及以上版本,请使用 新版配置方法 进行配置。 下载地址:https://mirrors.aliyun.com/kubernetes/ 新版下载地址:https://mirrors.aliyun.com/kubernetes-new/ 1.1 配置方法…

【日记】什么时候混到连信封都要从单位顺这种地步了……(1171 字)

正文早上 5 点半,被手机的暴雨红色预警吵醒了。它居然还会发出警报声,有点意外。当时翻身看手机,只见红红的一大片,我还以为是地震,给我瞬间吓清醒了。早上连发两个暴雨红色预警,中午消停了一会儿,晚上又开始发。今晚跟何老师清假了,说休息一天,怕去了之后回不来了。刚…

Kubernetes安装-kubeadm方式

环境 1.软件版本系统版本centos 7.9(内核采用4.19)docker 20.10.15kubeadm 1.22.172.ip划分主机名ip地址系统配置kubeadm-master 10.103.236.201 2core_2gkubeadm-node01 10.103.236.202 1core_2gkubeadm-node02 10.103.236.203 1core_2gkubeadm-node03 10.103.236.204 1core_2…

Redis高可用之持久化、主从复制

一、Redis高可用策略概述持久化 持久化是最简单的高可用方法,主要作用是数据备份,即将数据存储在硬盘,保证数据不会因进程退出而丢失。主从复制 主从复制是高可用Redis的基础,主要实现了数据的多机备份,以及对于读操作的负载均衡和简单的故障恢复哨兵 在主从复制的基础上,…

易优eyoucms后台登录地址能否更改?

请在功能地图-安全中心里修改本文来自博客园,作者:黄文Rex,转载请注明原文链接:https://www.cnblogs.com/hwrex/p/18295889

织梦DedeCMS怎么更换编辑器

入口: 系统 > 系统设置 > 系统基本参数 > 核心设置 > 编辑器默认可选参数: wangEditor 、 ckeditor 、 fck本文来自博客园,作者:黄文Rex,转载请注明原文链接:https://www.cnblogs.com/hwrex/p/18295890