经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Python3 » 查看文章
使用pyqt5制作简单计分桌面应用
来源:cnblogs  作者:东血  时间:2024/7/11 15:00:33  对本文有异议

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

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

ui设计

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

比赛准备阶段界面

image-20240711143434332

比赛进行中界面

image-20240711143507616

完整ui代码

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <ui version="4.0">
  3. <class>Form</class>
  4. <widget class="QWidget" name="Form">
  5. <property name="enabled">
  6. <bool>true</bool>
  7. </property>
  8. <property name="geometry">
  9. <rect>
  10. <x>0</x>
  11. <y>0</y>
  12. <width>1920</width>
  13. <height>1080</height>
  14. </rect>
  15. </property>
  16. <property name="minimumSize">
  17. <size>
  18. <width>1920</width>
  19. <height>1080</height>
  20. </size>
  21. </property>
  22. <property name="maximumSize">
  23. <size>
  24. <width>1920</width>
  25. <height>1080</height>
  26. </size>
  27. </property>
  28. <property name="windowTitle">
  29. <string>Form</string>
  30. </property>
  31. <widget class="QWidget" name="race_prepare_page" native="true">
  32. <property name="enabled">
  33. <bool>true</bool>
  34. </property>
  35. <property name="geometry">
  36. <rect>
  37. <x>440</x>
  38. <y>130</y>
  39. <width>1211</width>
  40. <height>721</height>
  41. </rect>
  42. </property>
  43. <property name="styleSheet">
  44. <string notr="true"/>
  45. </property>
  46. <widget class="QTableWidget" name="score_table_display">
  47. <property name="enabled">
  48. <bool>true</bool>
  49. </property>
  50. <property name="geometry">
  51. <rect>
  52. <x>580</x>
  53. <y>190</y>
  54. <width>621</width>
  55. <height>341</height>
  56. </rect>
  57. </property>
  58. <property name="styleSheet">
  59. <string notr="true">font: 20px ;</string>
  60. </property>
  61. </widget>
  62. <widget class="QLabel" name="score_display_label">
  63. <property name="geometry">
  64. <rect>
  65. <x>830</x>
  66. <y>540</y>
  67. <width>131</width>
  68. <height>41</height>
  69. </rect>
  70. </property>
  71. <property name="styleSheet">
  72. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  73. </property>
  74. <property name="text">
  75. <string>选手信息展示</string>
  76. </property>
  77. </widget>
  78. <widget class="QPushButton" name="race_info_button">
  79. <property name="geometry">
  80. <rect>
  81. <x>200</x>
  82. <y>660</y>
  83. <width>121</width>
  84. <height>51</height>
  85. </rect>
  86. </property>
  87. <property name="styleSheet">
  88. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  89. </property>
  90. <property name="text">
  91. <string>确认信息</string>
  92. </property>
  93. </widget>
  94. <widget class="QPushButton" name="race_start_button">
  95. <property name="geometry">
  96. <rect>
  97. <x>740</x>
  98. <y>90</y>
  99. <width>121</width>
  100. <height>51</height>
  101. </rect>
  102. </property>
  103. <property name="styleSheet">
  104. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  105. </property>
  106. <property name="text">
  107. <string>比赛开始</string>
  108. </property>
  109. </widget>
  110. <widget class="QLabel" name="race_preparation_label">
  111. <property name="geometry">
  112. <rect>
  113. <x>510</x>
  114. <y>10</y>
  115. <width>181</width>
  116. <height>41</height>
  117. </rect>
  118. </property>
  119. <property name="styleSheet">
  120. <string notr="true">font: 30px &quot;Adobe Arabic&quot;;</string>
  121. </property>
  122. <property name="text">
  123. <string>比赛准备阶段</string>
  124. </property>
  125. </widget>
  126. <widget class="QLabel" name="music_name_label">
  127. <property name="enabled">
  128. <bool>true</bool>
  129. </property>
  130. <property name="geometry">
  131. <rect>
  132. <x>10</x>
  133. <y>350</y>
  134. <width>91</width>
  135. <height>81</height>
  136. </rect>
  137. </property>
  138. <property name="styleSheet">
  139. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  140. </property>
  141. <property name="text">
  142. <string>请按选手排序输入曲名名称</string>
  143. </property>
  144. <property name="wordWrap">
  145. <bool>true</bool>
  146. </property>
  147. </widget>
  148. <widget class="QRadioButton" name="remove_yes">
  149. <property name="geometry">
  150. <rect>
  151. <x>250</x>
  152. <y>560</y>
  153. <width>61</width>
  154. <height>21</height>
  155. </rect>
  156. </property>
  157. <property name="styleSheet">
  158. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  159. </property>
  160. <property name="text">
  161. <string></string>
  162. </property>
  163. </widget>
  164. <widget class="QLineEdit" name="judge_number_input">
  165. <property name="geometry">
  166. <rect>
  167. <x>100</x>
  168. <y>110</y>
  169. <width>151</width>
  170. <height>31</height>
  171. </rect>
  172. </property>
  173. <property name="styleSheet">
  174. <string notr="true">font: 20px ;</string>
  175. </property>
  176. <property name="text">
  177. <string/>
  178. </property>
  179. <property name="placeholderText">
  180. <string>填写示例:1</string>
  181. </property>
  182. </widget>
  183. <widget class="QLabel" name="race_name_label">
  184. <property name="geometry">
  185. <rect>
  186. <x>10</x>
  187. <y>60</y>
  188. <width>91</width>
  189. <height>24</height>
  190. </rect>
  191. </property>
  192. <property name="styleSheet">
  193. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  194. </property>
  195. <property name="text">
  196. <string>比赛名称</string>
  197. </property>
  198. </widget>
  199. <widget class="QTextEdit" name="judge_namelist_input">
  200. <property name="geometry">
  201. <rect>
  202. <x>100</x>
  203. <y>160</y>
  204. <width>151</width>
  205. <height>171</height>
  206. </rect>
  207. </property>
  208. <property name="styleSheet">
  209. <string notr="true">font: 20px;</string>
  210. </property>
  211. <property name="markdown">
  212. <string/>
  213. </property>
  214. <property name="html">
  215. <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;
  216. &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;
  217. p, li { white-space: pre-wrap; }
  218. &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:20px; font-weight:400; font-style:normal;&quot;&gt;
  219. &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>
  220. </property>
  221. <property name="placeholderText">
  222. <string>填写示例: 张三 李四</string>
  223. </property>
  224. </widget>
  225. <widget class="QLabel" name="judge_number_label">
  226. <property name="geometry">
  227. <rect>
  228. <x>11</x>
  229. <y>116</y>
  230. <width>81</width>
  231. <height>24</height>
  232. </rect>
  233. </property>
  234. <property name="styleSheet">
  235. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  236. </property>
  237. <property name="text">
  238. <string>评委数量</string>
  239. </property>
  240. </widget>
  241. <widget class="QTextEdit" name="player_namelist_input">
  242. <property name="geometry">
  243. <rect>
  244. <x>390</x>
  245. <y>160</y>
  246. <width>151</width>
  247. <height>171</height>
  248. </rect>
  249. </property>
  250. <property name="styleSheet">
  251. <string notr="true">font: 20px;</string>
  252. </property>
  253. <property name="markdown">
  254. <string/>
  255. </property>
  256. <property name="html">
  257. <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;
  258. &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;
  259. p, li { white-space: pre-wrap; }
  260. &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:20px; font-weight:400; font-style:normal;&quot;&gt;
  261. &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>
  262. </property>
  263. <property name="placeholderText">
  264. <string>填写示例: 张三 李四</string>
  265. </property>
  266. </widget>
  267. <widget class="QLabel" name="player_name_label">
  268. <property name="geometry">
  269. <rect>
  270. <x>300</x>
  271. <y>160</y>
  272. <width>91</width>
  273. <height>81</height>
  274. </rect>
  275. </property>
  276. <property name="styleSheet">
  277. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  278. </property>
  279. <property name="text">
  280. <string>请按选手排序输入姓名</string>
  281. </property>
  282. <property name="wordWrap">
  283. <bool>true</bool>
  284. </property>
  285. </widget>
  286. <widget class="QLineEdit" name="race_name_input">
  287. <property name="geometry">
  288. <rect>
  289. <x>100</x>
  290. <y>54</y>
  291. <width>441</width>
  292. <height>31</height>
  293. </rect>
  294. </property>
  295. <property name="accessibleName">
  296. <string/>
  297. </property>
  298. <property name="styleSheet">
  299. <string notr="true">font: 20px;</string>
  300. </property>
  301. <property name="inputMask">
  302. <string/>
  303. </property>
  304. <property name="text">
  305. <string/>
  306. </property>
  307. <property name="placeholderText">
  308. <string>默认比赛</string>
  309. </property>
  310. </widget>
  311. <widget class="QLabel" name="judge_name_label">
  312. <property name="geometry">
  313. <rect>
  314. <x>10</x>
  315. <y>160</y>
  316. <width>91</width>
  317. <height>81</height>
  318. </rect>
  319. </property>
  320. <property name="styleSheet">
  321. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  322. </property>
  323. <property name="text">
  324. <string>请按评委排序输入姓名</string>
  325. </property>
  326. <property name="wordWrap">
  327. <bool>true</bool>
  328. </property>
  329. </widget>
  330. <widget class="QLineEdit" name="player_number_input">
  331. <property name="geometry">
  332. <rect>
  333. <x>390</x>
  334. <y>110</y>
  335. <width>151</width>
  336. <height>31</height>
  337. </rect>
  338. </property>
  339. <property name="styleSheet">
  340. <string notr="true">font: 20px ;</string>
  341. </property>
  342. <property name="text">
  343. <string/>
  344. </property>
  345. <property name="placeholderText">
  346. <string>填写示例:1</string>
  347. </property>
  348. </widget>
  349. <widget class="QRadioButton" name="remove_no">
  350. <property name="geometry">
  351. <rect>
  352. <x>340</x>
  353. <y>560</y>
  354. <width>51</width>
  355. <height>21</height>
  356. </rect>
  357. </property>
  358. <property name="styleSheet">
  359. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  360. </property>
  361. <property name="text">
  362. <string></string>
  363. </property>
  364. </widget>
  365. <widget class="QLabel" name="remove_score_label">
  366. <property name="geometry">
  367. <rect>
  368. <x>10</x>
  369. <y>614</y>
  370. <width>221</width>
  371. <height>24</height>
  372. </rect>
  373. </property>
  374. <property name="styleSheet">
  375. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  376. </property>
  377. <property name="text">
  378. <string>去掉几个最高分和最低分</string>
  379. </property>
  380. </widget>
  381. <widget class="QLineEdit" name="remove_score_input">
  382. <property name="geometry">
  383. <rect>
  384. <x>250</x>
  385. <y>610</y>
  386. <width>151</width>
  387. <height>31</height>
  388. </rect>
  389. </property>
  390. <property name="styleSheet">
  391. <string notr="true">font: 20px ;</string>
  392. </property>
  393. <property name="text">
  394. <string/>
  395. </property>
  396. <property name="placeholderText">
  397. <string>填写示例:1</string>
  398. </property>
  399. </widget>
  400. <widget class="QLabel" name="player_number_label">
  401. <property name="geometry">
  402. <rect>
  403. <x>300</x>
  404. <y>116</y>
  405. <width>91</width>
  406. <height>24</height>
  407. </rect>
  408. </property>
  409. <property name="styleSheet">
  410. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  411. </property>
  412. <property name="text">
  413. <string>选手数量</string>
  414. </property>
  415. </widget>
  416. <widget class="QLabel" name="remove_choose_label">
  417. <property name="geometry">
  418. <rect>
  419. <x>10</x>
  420. <y>560</y>
  421. <width>221</width>
  422. <height>24</height>
  423. </rect>
  424. </property>
  425. <property name="styleSheet">
  426. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  427. </property>
  428. <property name="text">
  429. <string>是否去掉最高分和最低分</string>
  430. </property>
  431. </widget>
  432. <widget class="QTextEdit" name="music_namelist_input">
  433. <property name="geometry">
  434. <rect>
  435. <x>100</x>
  436. <y>350</y>
  437. <width>441</width>
  438. <height>181</height>
  439. </rect>
  440. </property>
  441. <property name="styleSheet">
  442. <string notr="true">font: 20px;</string>
  443. </property>
  444. <property name="markdown">
  445. <string/>
  446. </property>
  447. <property name="html">
  448. <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;
  449. &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;
  450. p, li { white-space: pre-wrap; }
  451. &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'SimSun'; font-size:20px; font-weight:400; font-style:normal;&quot;&gt;
  452. &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>
  453. </property>
  454. <property name="placeholderText">
  455. <string>填写示例: 古典乐 爵士乐</string>
  456. </property>
  457. </widget>
  458. <widget class="QPushButton" name="continue_race_button">
  459. <property name="geometry">
  460. <rect>
  461. <x>890</x>
  462. <y>90</y>
  463. <width>151</width>
  464. <height>51</height>
  465. </rect>
  466. </property>
  467. <property name="styleSheet">
  468. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  469. </property>
  470. <property name="text">
  471. <string>继续上次比赛</string>
  472. </property>
  473. </widget>
  474. <widget class="QPushButton" name="quit_code_button">
  475. <property name="geometry">
  476. <rect>
  477. <x>1070</x>
  478. <y>90</y>
  479. <width>121</width>
  480. <height>51</height>
  481. </rect>
  482. </property>
  483. <property name="styleSheet">
  484. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  485. </property>
  486. <property name="text">
  487. <string>退出程序</string>
  488. </property>
  489. </widget>
  490. <widget class="QPushButton" name="save_info_button">
  491. <property name="geometry">
  492. <rect>
  493. <x>590</x>
  494. <y>90</y>
  495. <width>121</width>
  496. <height>51</height>
  497. </rect>
  498. </property>
  499. <property name="styleSheet">
  500. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  501. </property>
  502. <property name="text">
  503. <string>保存信息</string>
  504. </property>
  505. </widget>
  506. </widget>
  507. <widget class="QWidget" name="race_going_page" native="true">
  508. <property name="geometry">
  509. <rect>
  510. <x>440</x>
  511. <y>130</y>
  512. <width>1211</width>
  513. <height>721</height>
  514. </rect>
  515. </property>
  516. <widget class="QLabel" name="race_going_label">
  517. <property name="geometry">
  518. <rect>
  519. <x>0</x>
  520. <y>10</y>
  521. <width>1211</width>
  522. <height>41</height>
  523. </rect>
  524. </property>
  525. <property name="styleSheet">
  526. <string notr="true">font: 30px &quot;Adobe Arabic&quot;;</string>
  527. </property>
  528. <property name="text">
  529. <string>比赛进行阶段</string>
  530. </property>
  531. <property name="alignment">
  532. <set>Qt::AlignCenter</set>
  533. </property>
  534. </widget>
  535. <widget class="QLabel" name="judge_one_label_1">
  536. <property name="geometry">
  537. <rect>
  538. <x>80</x>
  539. <y>146</y>
  540. <width>181</width>
  541. <height>41</height>
  542. </rect>
  543. </property>
  544. <property name="styleSheet">
  545. <string notr="true">font: 20px;</string>
  546. </property>
  547. <property name="text">
  548. <string>姓名:1号评委</string>
  549. </property>
  550. </widget>
  551. <widget class="QLineEdit" name="judgeone_score_input_1">
  552. <property name="geometry">
  553. <rect>
  554. <x>300</x>
  555. <y>150</y>
  556. <width>151</width>
  557. <height>31</height>
  558. </rect>
  559. </property>
  560. <property name="styleSheet">
  561. <string notr="true">font: 20px ;</string>
  562. </property>
  563. <property name="text">
  564. <string/>
  565. </property>
  566. <property name="placeholderText">
  567. <string>填写示例:1</string>
  568. </property>
  569. </widget>
  570. <widget class="QLabel" name="judge_one_label_2">
  571. <property name="geometry">
  572. <rect>
  573. <x>81</x>
  574. <y>202</y>
  575. <width>181</width>
  576. <height>41</height>
  577. </rect>
  578. </property>
  579. <property name="styleSheet">
  580. <string notr="true">font: 20px;</string>
  581. </property>
  582. <property name="text">
  583. <string>姓名:2号评委</string>
  584. </property>
  585. </widget>
  586. <widget class="QLineEdit" name="judgeone_score_input_2">
  587. <property name="geometry">
  588. <rect>
  589. <x>301</x>
  590. <y>206</y>
  591. <width>151</width>
  592. <height>31</height>
  593. </rect>
  594. </property>
  595. <property name="styleSheet">
  596. <string notr="true">font: 20px ;</string>
  597. </property>
  598. <property name="text">
  599. <string/>
  600. </property>
  601. <property name="placeholderText">
  602. <string>填写示例:1</string>
  603. </property>
  604. </widget>
  605. <widget class="QLabel" name="judge_one_label_3">
  606. <property name="geometry">
  607. <rect>
  608. <x>81</x>
  609. <y>252</y>
  610. <width>181</width>
  611. <height>41</height>
  612. </rect>
  613. </property>
  614. <property name="styleSheet">
  615. <string notr="true">font: 20px;</string>
  616. </property>
  617. <property name="text">
  618. <string>姓名:3号评委</string>
  619. </property>
  620. </widget>
  621. <widget class="QLineEdit" name="judgeone_score_input_3">
  622. <property name="geometry">
  623. <rect>
  624. <x>301</x>
  625. <y>256</y>
  626. <width>151</width>
  627. <height>31</height>
  628. </rect>
  629. </property>
  630. <property name="styleSheet">
  631. <string notr="true">font: 20px ;</string>
  632. </property>
  633. <property name="text">
  634. <string/>
  635. </property>
  636. <property name="placeholderText">
  637. <string>填写示例:1</string>
  638. </property>
  639. </widget>
  640. <widget class="QLineEdit" name="judgeone_score_input_4">
  641. <property name="geometry">
  642. <rect>
  643. <x>300</x>
  644. <y>310</y>
  645. <width>151</width>
  646. <height>31</height>
  647. </rect>
  648. </property>
  649. <property name="styleSheet">
  650. <string notr="true">font: 20px ;</string>
  651. </property>
  652. <property name="text">
  653. <string/>
  654. </property>
  655. <property name="placeholderText">
  656. <string>填写示例:1</string>
  657. </property>
  658. </widget>
  659. <widget class="QLabel" name="judge_one_label_4">
  660. <property name="geometry">
  661. <rect>
  662. <x>80</x>
  663. <y>306</y>
  664. <width>181</width>
  665. <height>41</height>
  666. </rect>
  667. </property>
  668. <property name="styleSheet">
  669. <string notr="true">font: 20px;</string>
  670. </property>
  671. <property name="text">
  672. <string>姓名:4号评委</string>
  673. </property>
  674. </widget>
  675. <widget class="QLabel" name="judge_one_label_5">
  676. <property name="geometry">
  677. <rect>
  678. <x>81</x>
  679. <y>362</y>
  680. <width>181</width>
  681. <height>41</height>
  682. </rect>
  683. </property>
  684. <property name="styleSheet">
  685. <string notr="true">font: 20px;</string>
  686. </property>
  687. <property name="text">
  688. <string>姓名:5号评委</string>
  689. </property>
  690. </widget>
  691. <widget class="QLineEdit" name="judgeone_score_input_5">
  692. <property name="geometry">
  693. <rect>
  694. <x>301</x>
  695. <y>366</y>
  696. <width>151</width>
  697. <height>31</height>
  698. </rect>
  699. </property>
  700. <property name="styleSheet">
  701. <string notr="true">font: 20px ;</string>
  702. </property>
  703. <property name="text">
  704. <string/>
  705. </property>
  706. <property name="placeholderText">
  707. <string>填写示例:1</string>
  708. </property>
  709. </widget>
  710. <widget class="QLabel" name="judge_one_label_6">
  711. <property name="geometry">
  712. <rect>
  713. <x>81</x>
  714. <y>422</y>
  715. <width>181</width>
  716. <height>41</height>
  717. </rect>
  718. </property>
  719. <property name="styleSheet">
  720. <string notr="true">font: 20px;</string>
  721. </property>
  722. <property name="text">
  723. <string>姓名:6号评委</string>
  724. </property>
  725. </widget>
  726. <widget class="QLineEdit" name="judgeone_score_input_6">
  727. <property name="geometry">
  728. <rect>
  729. <x>301</x>
  730. <y>426</y>
  731. <width>151</width>
  732. <height>31</height>
  733. </rect>
  734. </property>
  735. <property name="styleSheet">
  736. <string notr="true">font: 20px ;</string>
  737. </property>
  738. <property name="text">
  739. <string/>
  740. </property>
  741. <property name="placeholderText">
  742. <string>填写示例:1</string>
  743. </property>
  744. </widget>
  745. <widget class="QLabel" name="judge_one_label_7">
  746. <property name="geometry">
  747. <rect>
  748. <x>81</x>
  749. <y>482</y>
  750. <width>181</width>
  751. <height>41</height>
  752. </rect>
  753. </property>
  754. <property name="styleSheet">
  755. <string notr="true">font: 20px;</string>
  756. </property>
  757. <property name="text">
  758. <string>姓名:7号评委</string>
  759. </property>
  760. </widget>
  761. <widget class="QLineEdit" name="judgeone_score_input_7">
  762. <property name="geometry">
  763. <rect>
  764. <x>301</x>
  765. <y>486</y>
  766. <width>151</width>
  767. <height>31</height>
  768. </rect>
  769. </property>
  770. <property name="styleSheet">
  771. <string notr="true">font: 20px ;</string>
  772. </property>
  773. <property name="text">
  774. <string/>
  775. </property>
  776. <property name="placeholderText">
  777. <string>填写示例:1</string>
  778. </property>
  779. </widget>
  780. <widget class="QLabel" name="judge_one_label_8">
  781. <property name="geometry">
  782. <rect>
  783. <x>81</x>
  784. <y>542</y>
  785. <width>181</width>
  786. <height>41</height>
  787. </rect>
  788. </property>
  789. <property name="styleSheet">
  790. <string notr="true">font: 20px;</string>
  791. </property>
  792. <property name="text">
  793. <string>姓名:8号评委</string>
  794. </property>
  795. </widget>
  796. <widget class="QLineEdit" name="judgeone_score_input_8">
  797. <property name="geometry">
  798. <rect>
  799. <x>301</x>
  800. <y>546</y>
  801. <width>151</width>
  802. <height>31</height>
  803. </rect>
  804. </property>
  805. <property name="styleSheet">
  806. <string notr="true">font: 20px ;</string>
  807. </property>
  808. <property name="text">
  809. <string/>
  810. </property>
  811. <property name="placeholderText">
  812. <string>填写示例:1</string>
  813. </property>
  814. </widget>
  815. <widget class="QLabel" name="judge_one_label_9">
  816. <property name="geometry">
  817. <rect>
  818. <x>81</x>
  819. <y>602</y>
  820. <width>181</width>
  821. <height>41</height>
  822. </rect>
  823. </property>
  824. <property name="styleSheet">
  825. <string notr="true">font: 20px;</string>
  826. </property>
  827. <property name="text">
  828. <string>姓名:9号评委</string>
  829. </property>
  830. </widget>
  831. <widget class="QLineEdit" name="judgeone_score_input_9">
  832. <property name="geometry">
  833. <rect>
  834. <x>301</x>
  835. <y>606</y>
  836. <width>151</width>
  837. <height>31</height>
  838. </rect>
  839. </property>
  840. <property name="styleSheet">
  841. <string notr="true">font: 20px ;</string>
  842. </property>
  843. <property name="text">
  844. <string/>
  845. </property>
  846. <property name="placeholderText">
  847. <string>填写示例:1</string>
  848. </property>
  849. </widget>
  850. <widget class="QLabel" name="judge_com_label_1">
  851. <property name="geometry">
  852. <rect>
  853. <x>510</x>
  854. <y>250</y>
  855. <width>151</width>
  856. <height>41</height>
  857. </rect>
  858. </property>
  859. <property name="styleSheet">
  860. <string notr="true">font: 24px;</string>
  861. </property>
  862. <property name="text">
  863. <string>最高分:</string>
  864. </property>
  865. </widget>
  866. <widget class="QLabel" name="judge_com_label_2">
  867. <property name="geometry">
  868. <rect>
  869. <x>700</x>
  870. <y>250</y>
  871. <width>161</width>
  872. <height>41</height>
  873. </rect>
  874. </property>
  875. <property name="styleSheet">
  876. <string notr="true">font: 24px;</string>
  877. </property>
  878. <property name="text">
  879. <string>最低分:</string>
  880. </property>
  881. </widget>
  882. <widget class="QLabel" name="judge_com_label_3">
  883. <property name="geometry">
  884. <rect>
  885. <x>510</x>
  886. <y>320</y>
  887. <width>151</width>
  888. <height>41</height>
  889. </rect>
  890. </property>
  891. <property name="styleSheet">
  892. <string notr="true">font: 30px;</string>
  893. </property>
  894. <property name="text">
  895. <string>实际得分:</string>
  896. </property>
  897. </widget>
  898. <widget class="QLabel" name="judge_com_label_4">
  899. <property name="geometry">
  900. <rect>
  901. <x>670</x>
  902. <y>300</y>
  903. <width>181</width>
  904. <height>81</height>
  905. </rect>
  906. </property>
  907. <property name="styleSheet">
  908. <string notr="true">font: 60px;</string>
  909. </property>
  910. <property name="text">
  911. <string/>
  912. </property>
  913. </widget>
  914. <widget class="QPushButton" name="next_player_button">
  915. <property name="geometry">
  916. <rect>
  917. <x>630</x>
  918. <y>170</y>
  919. <width>151</width>
  920. <height>51</height>
  921. </rect>
  922. </property>
  923. <property name="styleSheet">
  924. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  925. </property>
  926. <property name="text">
  927. <string>下一个选手</string>
  928. </property>
  929. </widget>
  930. <widget class="QPushButton" name="exit_race_button">
  931. <property name="geometry">
  932. <rect>
  933. <x>970</x>
  934. <y>170</y>
  935. <width>151</width>
  936. <height>51</height>
  937. </rect>
  938. </property>
  939. <property name="styleSheet">
  940. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  941. </property>
  942. <property name="text">
  943. <string>比赛结束</string>
  944. </property>
  945. </widget>
  946. <widget class="QLabel" name="current_player_label">
  947. <property name="geometry">
  948. <rect>
  949. <x>80</x>
  950. <y>90</y>
  951. <width>1091</width>
  952. <height>41</height>
  953. </rect>
  954. </property>
  955. <property name="styleSheet">
  956. <string notr="true">font: 24px;</string>
  957. </property>
  958. <property name="text">
  959. <string>当前选手:</string>
  960. </property>
  961. </widget>
  962. <widget class="QPushButton" name="player_quit_button">
  963. <property name="geometry">
  964. <rect>
  965. <x>800</x>
  966. <y>170</y>
  967. <width>151</width>
  968. <height>51</height>
  969. </rect>
  970. </property>
  971. <property name="styleSheet">
  972. <string notr="true">font: 20px &quot;Adobe Arabic&quot;;</string>
  973. </property>
  974. <property name="text">
  975. <string>当前选手弃权</string>
  976. </property>
  977. </widget>
  978. </widget>
  979. </widget>
  980. <resources/>
  981. <connections/>
  982. </ui>

代码设计

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

  1. from PyQt5.QtGui import *
  2. from PyQt5.QtWidgets import *
  3. from PyQt5.QtCore import *
  4. from PyQt5 import uic
  5. import keyboard
  6. import sys
  7. import os
  8. import pandas as pd
  9. import docx
  10. def get_path(relative_path):
  11. try:
  12. base_path = sys._MEIPASS
  13. except AttributeError:
  14. base_path = os.path.abspath(".")
  15. return os.path.normpath(os.path.join(base_path, relative_path))
  16. def get_decimal_places(num):
  17. import decimal
  18. if '.' in str(num):
  19. num = str(float(num)) #如果传入的是字符串形式的浮点数,先去掉小数后面无意义的0
  20. d = decimal.Decimal(str(num))
  21. return abs(d.as_tuple().exponent)
  22. def del_files(path_file):
  23. ls = os.listdir(path_file)
  24. for i in ls:
  25. f_path = os.path.join(path_file, i)
  26. # 判断是否是一个目录,若是,则递归删除
  27. if os.path.isdir(f_path):
  28. del_files(f_path)
  29. else:
  30. os.remove(f_path)
  31. class MyWindow(QWidget):
  32. def __init__(self):
  33. super().__init__()
  34. self.ui = uic.loadUi(get_path("assets/comscore_final.ui")) #读取ui文件
  35. # 展示窗口
  36. self.ui.setWindowTitle('比赛计分系统')
  37. self.ui.setWindowFlag(Qt.WindowCloseButtonHint, False)
  38. #提取每个要使用的控件
  39. #比赛准备阶段
  40. self.race_prepare=self.ui.race_prepare_page #比赛准备页面
  41. self.race_name=self.ui.race_name_input #比赛名称
  42. self.judge_number=self.ui.judge_number_input #评委数量
  43. self.judge_namelist=self.ui.judge_namelist_input #评委信息
  44. self.player_number=self.ui.player_number_input #选手数量
  45. self.player_namelist=self.ui.player_namelist_input #选手信息
  46. self.music_namelist=self.ui.music_namelist_input #音乐信息
  47. self.race_info=self.ui.race_info_button #确认信息按钮
  48. self.continue_race=self.ui.continue_race_button #继续上次比赛按钮
  49. self.race_start=self.ui.race_start_button #比赛开始按钮'
  50. self.remove_score=self.ui.remove_score_input
  51. self.save_info=self.ui.save_info_button #保存信息
  52. self.quit_code=self.ui.quit_code_button #退出程序
  53. self.race_start.setEnabled(False)
  54. self.save_info.setEnabled(False)
  55. #是否去掉最高分和最低分
  56. self.remove_yes_radiobox=self.ui.remove_yes
  57. self.remove_no_radiobox=self.ui.remove_no
  58. #去掉最高分和最低分的数量
  59. self.remove_score_label_now=self.ui.remove_score_label
  60. self.remove_score=self.ui.remove_score_input
  61. #默认选择不去掉,并且设置不显示去掉几个最高分和最低分的框
  62. self.remove_no_radiobox.setChecked(True)
  63. self.remove_score.setVisible(False) #初始设置隐藏
  64. self.remove_score_label_now.setVisible(False) #初始设置隐藏
  65. #toggled信号与槽函数绑定
  66. self.remove_yes_radiobox.toggled.connect(lambda :self.func_radiobox_btnstate(self.remove_yes_radiobox))
  67. self.remove_no_radiobox.toggled.connect(lambda :self.func_radiobox_btnstate(self.remove_no_radiobox))
  68. #选手信息展示
  69. self.score_table=self.ui.score_table_display #选手信息展示
  70. # 绑定信号与槽函数
  71. self.race_info.clicked.connect(self.func_race_info) #信息导入
  72. self.continue_race.clicked.connect(self.func_continue_race)# 根据文件来读取信息
  73. self.race_start.clicked.connect(self.func_race_start) #比赛开始按钮
  74. self.save_info.clicked.connect(self.func_save_info) #保存信息
  75. self.quit_code.clicked.connect(self.func_quit_code)
  76. #选手信息展示区域函数
  77. self.score_table.setSelectionMode(QAbstractItemView.SingleSelection)#设置选取方式为单个选取
  78. self.score_table.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) #设置水平滚动
  79. self.score_table.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) #设置竖直滚动
  80. #---------------------------------------------------------------------------------------------------------------------
  81. #---------------------------------------------------------------------------------------------------------------------
  82. #比赛进行阶段
  83. self.race_going=self.ui.race_going_page #比赛进行页面
  84. self.race_going.setVisible(False) #初始设置隐藏
  85. self.race_going_name=self.ui.race_going_label
  86. #当前选手
  87. self.current_player=self.ui.current_player_label
  88. #评委列表
  89. self.judge_one_1=self.ui.judge_one_label_1
  90. self.judgeone_score_1=self.ui.judgeone_score_input_1
  91. #设置校验规则,实例化浮点校验器,并设置范围0~10,精度为小数点两位
  92. myValidator = QRegExpValidator(QRegExp("^(10|\d(\.\d{1,2})?)$"))
  93. #初始设置隐藏
  94. for show_i in range(1,10):
  95. judge_one_label_name="judge_one_label_"+str(show_i)
  96. judge_one_temp = self.race_going.findChild(QLabel,judge_one_label_name)
  97. judge_one_temp.setVisible(False)
  98. judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  99. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  100. judgeone_score_temp.setVisible(False)
  101. #设置校验规则,限制只能输入数字还有小数后两位
  102. judgeone_score_temp.returnPressed.connect(self.func_text_change)
  103. judgeone_score_temp.setValidator(myValidator)
  104. #最高分,最低分,实际得分
  105. self.judge_com_max=self.ui.judge_com_label_1 #最高分
  106. self.judge_com_min=self.ui.judge_com_label_2 #最低分
  107. self.judge_com_average_label=self.ui.judge_com_label_3 #实际得分标签
  108. self.judge_com_average=self.ui.judge_com_label_4 #分数
  109. for show_i in range(1,5):
  110. judge_com_label_name="judge_com_label_"+str(show_i)
  111. judge_com_temp = self.race_going.findChild(QLabel,judge_com_label_name)
  112. judge_com_temp.setVisible(False)
  113. #计算总分按钮
  114. # self.com_score=self.ui.com_score_button
  115. #下一个选手按钮
  116. self.next_player=self.ui.next_player_button
  117. #比赛结束按钮
  118. self.exit_race=self.ui.exit_race_button
  119. #选手弃权按钮
  120. self.player_quit=self.ui.player_quit_button
  121. # 绑定信号与槽函数
  122. # self.com_score.clicked.connect(self.func_com_score) #计算总分
  123. self.next_player.clicked.connect(self.func_next_player) #下一个选手
  124. self.exit_race.clicked.connect(self.func_exit_race) #结束比赛
  125. self.player_quit.clicked.connect(self.func_player_quit) #选手弃权
  126. #赋予一个全局使用的数据变量
  127. self.all_data_df=[]
  128. self.have_score_number=0 #表示当前已经计分的选手数量
  129. self.remove_score_number=0
  130. def func_save_info(self):
  131. reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否保存信息?',QMessageBox.Question)
  132. if reply_one == QMessageBox.Yes:
  133. #先将读取的数据保存起来,以tablewight数据表信息为准
  134. player_index=[]
  135. player_name=[]
  136. music_name=[]
  137. for qtable_row in range(int(self.player_number.text())):
  138. player_index.append(self.score_table.item(qtable_row,0).text()) #获取某行某列item中的x信息
  139. player_name.append(self.score_table.item(qtable_row,1).text()) #获取某行某列item中的x信息
  140. music_name.append(self.score_table.item(qtable_row,2).text()) #获取某行某列item中的x信息
  141. judge_all_list=[]
  142. for qtable_column in range(int(self.judge_number.text())):
  143. judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  144. judge_all_list.append(judge_one_list)
  145. # creating the DataFrame
  146. all_data = pd.DataFrame(list(zip(player_index, player_name, music_name)))
  147. all_data.columns =['抽签序号', '选手姓名', '曲目名称'] #设置列名
  148. judge_namelist_temp=self.judge_namelist.toPlainText().split('\n')
  149. for qtable_column in range(int(self.judge_number.text())):
  150. judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  151. judge_column_name=judge_namelist_temp[qtable_column]+":"+str(qtable_column+1)+"号评委"
  152. all_data[judge_column_name]=judge_one_list
  153. #增加最高分,最低分列 ,增加实际得分列
  154. if self.remove_yes_radiobox.isChecked()==True:
  155. max_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  156. all_data['最高分']=max_one_list
  157. min_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  158. all_data['最低分']=min_one_list
  159. visual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格
  160. all_data['实得分']=visual_one_list
  161. index_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  162. all_data['最终排名']=index_one_list
  163. remove_score_str=self.remove_score.text()
  164. self.remove_score_number=int(self.remove_score.text())
  165. remove_one_list=[remove_score_str]*int(self.player_number.text()) #将列数据全部填充为空格
  166. all_data['去掉几个最高分']=remove_one_list
  167. else:
  168. visual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格
  169. all_data['实得分']=visual_one_list
  170. index_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  171. all_data['最终排名']=index_one_list
  172. remove_one_list=['0']*int(self.player_number.text()) #将列数据全部填充为空格
  173. all_data['去掉几个最高分']=remove_one_list
  174. all_data['抽签序号']=all_data['抽签序号'].astype(int)
  175. all_data=all_data.sort_values(by=['抽签序号']) #按照抽签序号排序
  176. all_data=all_data.reset_index(drop=True) #重新排列一下索引
  177. all_data.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引
  178. #恢复所有数据初始状态
  179. self.all_data_df=[]
  180. self.have_score_number=0 #表示当前已经计分的选手数量
  181. self.remove_score_number=0
  182. #默认选择不去掉,并且设置不显示去掉几个最高分和最低分的框
  183. self.remove_no_radiobox.setChecked(True)
  184. self.remove_score.setVisible(False) #初始设置隐藏
  185. self.remove_score_label_now.setVisible(False) #初始设置隐藏
  186. #然后要清空所有的输入
  187. self.race_name.setText("") #比赛名称
  188. self.judge_number.setText("") #评委数量
  189. self.judge_namelist.setText("") #评委信息
  190. self.player_number.setText("") #选手数量
  191. self.player_namelist.setText("") #选手信息
  192. self.music_namelist.setText("") #音乐信息
  193. #然后清空qtablewight
  194. self.score_table.setRowCount(0)
  195. self.score_table.setColumnCount(0)
  196. self.score_table.clearContents()
  197. #设置按钮不可用
  198. self.race_start.setEnabled(False)
  199. self.save_info.setEnabled(False)
  200. self.setQMessageBoxoneButtonTextENToCN("提示","保存信息成功",QMessageBox.Information)
  201. return
  202. else:
  203. self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)
  204. return
  205. return
  206. return
  207. def func_quit_code(self):
  208. reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否退出程序?',QMessageBox.Question)
  209. if reply_one == QMessageBox.Yes:
  210. self.setQMessageBoxoneButtonTextENToCN("提示","退出程序成功",QMessageBox.Information)
  211. sys.exit(0)
  212. return
  213. else:
  214. self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)
  215. return
  216. return
  217. def func_text_change(self):
  218. #在输入框内按下enter,就会进入这里
  219. #获取数据,保存这个选手的得分到临时表格中
  220. all_data_temp=self.all_data_df
  221. judge_number=0
  222. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  223. judge_number=int(all_data_temp.shape[1])-8
  224. else:
  225. judge_number=int(all_data_temp.shape[1])-6
  226. #遍历所有输入框,然后找到第一个为空的输入框,设置它为setFocus即可
  227. for com_i in range(1,judge_number+1):
  228. judgeone_score_input_name="judgeone_score_input_"+str(com_i)
  229. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  230. if judgeone_score_temp.text()=='':
  231. judgeone_score_temp.setFocus()
  232. return
  233. else:
  234. continue
  235. #获取数据,保存这个选手的得分到临时表格中
  236. all_data_temp=self.all_data_df
  237. print(self.all_data_df)
  238. reply_zero=self.setQMessageBoxtwoButtonTextENToCN('提示', '评委得分是否输入正确?',QMessageBox.Question)
  239. if reply_zero == QMessageBox.Yes:
  240. #根据评委数量来获取输入框数据
  241. score_list_temp=[]
  242. save_score_list=[]
  243. judge_number=0
  244. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  245. judge_number=int(all_data_temp.shape[1])-8
  246. else:
  247. judge_number=int(all_data_temp.shape[1])-6
  248. print(judge_number)
  249. for com_i in range(1,judge_number+1):
  250. judgeone_score_input_name="judgeone_score_input_"+str(com_i)
  251. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  252. judgeone_score_temp.setReadOnly(True) #设置为只读
  253. if judgeone_score_temp.text()=='':
  254. self.setQMessageBoxoneButtonTextENToCN("提示",str(com_i)+"评委分数未填写",QMessageBox.Information)
  255. return
  256. else:
  257. score_list_temp.append(float(judgeone_score_temp.text()))
  258. save_score_list.append(float(judgeone_score_temp.text()))
  259. print(score_list_temp)
  260. score_list_temp.sort() #对打分进行排序
  261. #设置最高分
  262. score_list_temp_max=max(score_list_temp)
  263. self.judge_com_max.setText("最高分: "+str(score_list_temp_max))
  264. # self.score_table.setText(score_list_temp_max)
  265. #设置最低分
  266. score_list_temp_min=min(score_list_temp)
  267. self.judge_com_min.setText("最低分: "+str(score_list_temp_min))
  268. for flag in range(self.remove_score_number):
  269. score_list_temp.pop() #删除最后一项
  270. score_list_temp.pop(0) #删除第一项
  271. #设置最终分数
  272. average_score=round(sum(score_list_temp)/len(score_list_temp),3)
  273. #设置
  274. self.judge_com_average.setText(str(average_score))
  275. #确定当前计算的是哪个选手,至少有一个评委
  276. current_player_row=0
  277. player_row=int(all_data_temp.shape[0])
  278. for player_row_index in range(0,player_row):
  279. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))
  280. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')
  281. 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':
  282. current_player_row=player_row_index
  283. break
  284. current_player_row=player_row_index
  285. self.have_score_number=current_player_row
  286. #保存方法在有最高分和没有最高分时有所不同,有
  287. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  288. #将这里面的数据进行覆盖 操作的是save_score_list,score_list_temp_max,score_list_temp_min
  289. print(save_score_list)
  290. for judge_number_index in range(0,judge_number):
  291. print(judge_number_index)
  292. all_data_temp.iloc[current_player_row,judge_number_index+3]=save_score_list[judge_number_index]
  293. all_data_temp.iloc[current_player_row,judge_number_index+4]=score_list_temp_max
  294. all_data_temp.iloc[current_player_row,judge_number_index+5]=score_list_temp_min
  295. all_data_temp.iloc[current_player_row,judge_number_index+6]=average_score
  296. else:
  297. for judge_number_index in range(0,judge_number):
  298. all_data_temp.iloc[current_player_row,judge_number_index+3]=save_score_list[judge_number_index]
  299. all_data_temp.iloc[current_player_row,judge_number_index+4]=average_score
  300. #重新保存数据表,最后再赋值回去
  301. all_data_temp.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引
  302. self.all_data_df=all_data_temp
  303. print(self.all_data_df)
  304. # #清空分数框
  305. # for show_i in range(1,judge_number+1):
  306. # judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  307. # judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  308. # judgeone_score_temp.clear()
  309. self.have_score_number=self.have_score_number+1 #保存当前选手序号,只用于验证选手是否弃权
  310. print("self.have_score_number=",self.have_score_number)
  311. return
  312. else:
  313. self.setQMessageBoxoneButtonTextENToCN("提示","请检查后,继续填写",QMessageBox.Information)
  314. return
  315. return
  316. #单选按钮绑定
  317. def func_radiobox_btnstate(self,btn):
  318. #输出按钮1与按钮2的状态,选中还是没选中
  319. if btn.text()=='是':
  320. if btn.isChecked()==True:
  321. # print(btn.text()+"is selected")
  322. self.remove_score.setVisible(True) #初始设置隐藏
  323. self.remove_score_label_now.setVisible(True) #初始设置隐藏
  324. else:
  325. # print(btn.text()+"is deselected")
  326. return
  327. if btn.text()=="否":
  328. if btn.isChecked() == True:
  329. # print(btn.text() + "is selected")
  330. self.remove_score.setVisible(False) #初始设置隐藏
  331. self.remove_score_label_now.setVisible(False) #初始设置隐藏
  332. self.remove_score.setText("") #重新设置为空
  333. else:
  334. # print(btn.text() + "is deselected")
  335. return
  336. def setQMessageBoxtwoButtonTextENToCN(self,windowTitle, text, qmessageIcon):
  337. """
  338. 设置需要的QMessageBox的按钮提示为中文
  339. :param qmessageIcon: 显示图标 例如QMessageBox.Question
  340. :param kwargs: 确定=QMessageBox.AcceptRole
  341. """
  342. msgBox = QMessageBox()
  343. msgBox.setWindowTitle(windowTitle)
  344. msgBox.setText(text)
  345. msgBox.setIcon(qmessageIcon)
  346. msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
  347. buttonY = msgBox.button(QMessageBox.Yes)
  348. buttonY.setText('是')
  349. buttonN = msgBox.button(QMessageBox.No)
  350. buttonN.setText('否')
  351. ret=msgBox.exec_()
  352. return ret
  353. def setQMessageappENToCN(self,windowTitle, text, qmessageIcon):
  354. """
  355. 设置需要的QMessageBox的按钮提示为中文
  356. :param qmessageIcon: 显示图标 例如QMessageBox.Question
  357. :param kwargs: 确定=QMessageBox.AcceptRole
  358. """
  359. msgBox = QMessageBox()
  360. msgBox.setWindowTitle(windowTitle)
  361. msgBox.setText(text)
  362. msgBox.setIcon(qmessageIcon)
  363. msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
  364. buttonY = msgBox.button(QMessageBox.Yes)
  365. buttonY.setText('比赛暂停')
  366. buttonN = msgBox.button(QMessageBox.No)
  367. buttonN.setText('比赛结束')
  368. ret=msgBox.exec_()
  369. return ret
  370. def setQMessageBoxoneButtonTextENToCN(self,windowTitle, text, qmessageIcon):
  371. """
  372. 设置需要的QMessageBox的按钮提示为中文
  373. :param qmessageIcon: 显示图标 例如QMessageBox.Question
  374. :param kwargs: 确定=QMessageBox.AcceptRole
  375. """
  376. msgBox = QMessageBox()
  377. msgBox.setWindowTitle(windowTitle)
  378. msgBox.setText(text)
  379. msgBox.setIcon(qmessageIcon)
  380. msgBox.setStandardButtons(QMessageBox.Yes)
  381. buttonY = msgBox.button(QMessageBox.Yes)
  382. buttonY.setText('是')
  383. msgBox.exec_()
  384. #根据输入框来读取信息已经无误
  385. def func_race_info(self):
  386. reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否确认比赛准备信息无误?',QMessageBox.Question)
  387. if reply_one == QMessageBox.No:
  388. self.setQMessageBoxoneButtonTextENToCN("提示","请继续填写",QMessageBox.Information)
  389. return
  390. #检查是否有未填写数据
  391. 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()=='':
  392. self.setQMessageBoxoneButtonTextENToCN("提示","有未填写数据",QMessageBox.Information)
  393. return
  394. if self.remove_score.text()=='' and self.remove_yes_radiobox.isChecked()==True:
  395. self.setQMessageBoxoneButtonTextENToCN("提示","有未填写数据",QMessageBox.Information)
  396. return
  397. #检查评委数量是否足够
  398. if int(self.judge_number.text())!=len(self.judge_namelist.toPlainText().split('\n')):
  399. self.setQMessageBoxoneButtonTextENToCN("提示","评委数量与评委姓名数量不对应,请重新填写",QMessageBox.Information)
  400. return
  401. #检查选手数量是否足够
  402. if int(self.player_number.text())!=len(self.player_namelist.toPlainText().split('\n')):
  403. self.setQMessageBoxoneButtonTextENToCN("提示","选手数量与选手姓名数量不对应,请重新填写",QMessageBox.Information)
  404. return
  405. #检查曲目数量是否足够
  406. if int(self.player_number.text())!=len(self.music_namelist.toPlainText().split('\n')):
  407. self.setQMessageBoxoneButtonTextENToCN("提示","音乐数量与选手数量不对应,请重新填写",QMessageBox.Information)
  408. return
  409. if reply_one == QMessageBox.Yes:
  410. self.setQMessageBoxoneButtonTextENToCN("提示","比赛准备信息填写成功",QMessageBox.Information)
  411. self.score_table.setColumnCount(3)
  412. self.score_table.setRowCount(int(self.player_number.text()))
  413. column_namelist_temp=["抽签序号","选手姓名","曲目名称"]
  414. self.score_table.setHorizontalHeaderLabels(column_namelist_temp) #设置行表头
  415. player_namelist_temp=self.player_namelist.toPlainText().split('\n')
  416. music_namelist_temp=self.music_namelist.toPlainText().split('\n')
  417. for i in range(int(self.player_number.text())):
  418. self.score_table.setItem(i,0, QTableWidgetItem(str(i+1)))
  419. self.score_table.setItem(i,1, QTableWidgetItem(player_namelist_temp[i]))
  420. self.score_table.setItem(i,2, QTableWidgetItem(music_namelist_temp[i]))
  421. #设置按钮可用
  422. self.race_start.setEnabled(True)
  423. self.save_info.setEnabled(True)
  424. #给设置自适应宽度
  425. self.score_table.resizeColumnToContents(0)
  426. self.score_table.resizeColumnToContents(1)
  427. self.score_table.resizeColumnToContents(2)
  428. return
  429. return
  430. #这是按照全新比赛的操作
  431. def func_race_start(self):
  432. #先将读取的数据保存起来,以tablewight数据表信息为准
  433. player_index=[]
  434. player_name=[]
  435. music_name=[]
  436. for qtable_row in range(int(self.player_number.text())):
  437. player_index.append(self.score_table.item(qtable_row,0).text()) #获取某行某列item中的x信息
  438. player_name.append(self.score_table.item(qtable_row,1).text()) #获取某行某列item中的x信息
  439. music_name.append(self.score_table.item(qtable_row,2).text()) #获取某行某列item中的x信息
  440. judge_all_list=[]
  441. for qtable_column in range(int(self.judge_number.text())):
  442. judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  443. judge_all_list.append(judge_one_list)
  444. # creating the DataFrame
  445. all_data = pd.DataFrame(list(zip(player_index, player_name, music_name)))
  446. all_data.columns =['抽签序号', '选手姓名', '曲目名称'] #设置列名
  447. judge_namelist_temp=self.judge_namelist.toPlainText().split('\n')
  448. for qtable_column in range(int(self.judge_number.text())):
  449. judge_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  450. judge_column_name=judge_namelist_temp[qtable_column]+":"+str(qtable_column+1)+"号评委"
  451. all_data[judge_column_name]=judge_one_list
  452. #增加最高分,最低分列 ,增加实际得分列
  453. if self.remove_yes_radiobox.isChecked()==True:
  454. max_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  455. all_data['最高分']=max_one_list
  456. min_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  457. all_data['最低分']=min_one_list
  458. visual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格
  459. all_data['实得分']=visual_one_list
  460. index_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  461. all_data['最终排名']=index_one_list
  462. remove_score_str=self.remove_score.text()
  463. self.remove_score_number=int(self.remove_score.text())
  464. remove_one_list=[remove_score_str]*int(self.player_number.text()) #将列数据全部填充为空格
  465. all_data['去掉几个最高分']=remove_one_list
  466. else:
  467. visual_one_list=[-1]*int(self.player_number.text()) #将列数据全部填充为空格
  468. all_data['实得分']=visual_one_list
  469. index_one_list=[' ']*int(self.player_number.text()) #将列数据全部填充为空格
  470. all_data['最终排名']=index_one_list
  471. remove_one_list=['0']*int(self.player_number.text()) #将列数据全部填充为空格
  472. all_data['去掉几个最高分']=remove_one_list
  473. all_data['抽签序号']=all_data['抽签序号'].astype(int)
  474. all_data=all_data.sort_values(by=['抽签序号']) #按照抽签序号排序
  475. all_data=all_data.reset_index(drop=True) #重新排列一下索引
  476. all_data.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引
  477. self.all_data_df=all_data
  478. #界面展示与隐藏
  479. self.race_prepare.setVisible(False) #初始设置隐藏
  480. self.race_going.setVisible(True) #初始设置隐藏
  481. #设置比赛名称
  482. self.race_going_name.setText(self.race_name.text())
  483. # 展示当前选手信息,需要读取数据表的1号来展示
  484. self.current_player.setText("当前选手:1号选手"+str(all_data.loc[0,'选手姓名']))
  485. #根据评委数量来显示评委框
  486. judge_number=int(self.judge_number.text())
  487. judge_one_namelist=self.judge_namelist.toPlainText().split('\n')
  488. for show_i in range(1,judge_number+1):
  489. judge_one_label_name="judge_one_label_"+str(show_i)
  490. judge_one_temp = self.race_going.findChild(QLabel,judge_one_label_name)
  491. #设置评委label的text
  492. judge_one_temp.setText(judge_one_namelist[show_i-1]+":"+str(show_i)+"号评委")
  493. judge_one_temp.setVisible(True)
  494. judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  495. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  496. judgeone_score_temp.setVisible(True)
  497. #根据是否需要去掉最高分和最低分来展示
  498. if self.remove_yes_radiobox.isChecked()==True:
  499. #去掉了最高分和最低分,那么就显示所有的
  500. for show_i in range(1,5):
  501. judge_com_label_name="judge_com_label_"+str(show_i)
  502. judge_com_temp = self.race_going.findChild(QLabel,judge_com_label_name)
  503. judge_com_temp.setVisible(True)
  504. else:
  505. #不去掉,则只显示,实际得分
  506. self.judge_com_average_label.setVisible(True)
  507. self.judge_com_average.setVisible(True)
  508. return
  509. #下一个选手
  510. def func_next_player(self):
  511. #获取数据,保存这个选手的得分到临时表格中
  512. all_data_temp=self.all_data_df
  513. print(self.all_data_df)
  514. #先询问是否计算最终得分,获取输入框信息,计算得分,然后展示出来,展示出来之后将信息保存到临时数据表中
  515. reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否跳到下一个选手?',QMessageBox.Question)
  516. if reply_one == QMessageBox.Yes:
  517. #先判断选手是否是弃权
  518. #确定当前计算的是哪个选手,至少有一个评委
  519. current_player_row=0
  520. #找到第一个未计分的选手
  521. player_row=int(all_data_temp.shape[0])
  522. print("player_row=",player_row)
  523. for player_row_index in range(0,player_row):
  524. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))
  525. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')
  526. 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':
  527. current_player_row=player_row_index
  528. break
  529. current_player_row=player_row_index
  530. self.have_score_number=current_player_row+1
  531. print("current_player_row=",current_player_row)
  532. print("player_row=",player_row)
  533. print("self.have_score_number=",self.have_score_number)
  534. if self.have_score_number==player_row:
  535. #这时候比赛就提示已经统计完所有选手分数
  536. self.setQMessageBoxoneButtonTextENToCN("提示","已统计完所有选手分数",QMessageBox.Information)
  537. self.current_player.setText("本场比赛所有选手已比赛完毕,请退出程序")
  538. #保存方法在有最高分和没有最高分时有所不同,有
  539. judge_number=0
  540. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  541. judge_number=int(all_data_temp.shape[1])-8
  542. else:
  543. judge_number=int(all_data_temp.shape[1])-6
  544. #清空分数框
  545. for show_i in range(1,judge_number+1):
  546. judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  547. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  548. judgeone_score_temp.clear()
  549. # judgeone_score_temp.setReadOnly(False) #恢复成可修改
  550. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  551. #设置最高分
  552. self.judge_com_max.setText("最高分: ")
  553. #设置最低分
  554. self.judge_com_min.setText("最低分: ")
  555. #设置最终分数
  556. self.judge_com_average.setText(str(''))
  557. else:
  558. #设置最终分数
  559. self.judge_com_average.setText(str(''))
  560. self.judgeone_score_1.setFocus() #设置光标
  561. #设置按钮不可点击
  562. self.next_player.setEnabled(False)
  563. #选手弃权按钮
  564. self.player_quit.setEnabled(False)
  565. return
  566. else:
  567. judge_number=0
  568. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  569. judge_number=int(all_data_temp.shape[1])-8
  570. else:
  571. judge_number=int(all_data_temp.shape[1])-6
  572. #current_player_row表示当前第一个空的数据选手序号,self.have_score_number表示已经填写的选手数据序号,
  573. # 如果不一样,说明这个选手弃权了,需要把所有数据填写完毕
  574. # 如果计算数据表里的和当前的一样,那就说明没有弃权
  575. print("self.have_score_number=",self.have_score_number)
  576. print("current_player_row=",current_player_row)
  577. #正常切换,只需要重新设置一些信息即可
  578. #清空分数框
  579. for show_i in range(1,judge_number+1):
  580. judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  581. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  582. judgeone_score_temp.clear()
  583. judgeone_score_temp.setReadOnly(False) #恢复成可修改
  584. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  585. #重新设置文字信息
  586. #设置下一个选手
  587. self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")
  588. #设置最高分
  589. self.judge_com_max.setText("最高分: ")
  590. #设置最低分
  591. self.judge_com_min.setText("最低分: ")
  592. #设置最终分数
  593. self.judge_com_average.setText(str(''))
  594. else:
  595. #设置下一个选手
  596. self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")
  597. #设置最终分数
  598. self.judge_com_average.setText(str(''))
  599. self.judgeone_score_1.setFocus() #设置光标
  600. return
  601. return
  602. else:
  603. self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)
  604. return
  605. return
  606. def func_player_quit(self):
  607. #获取数据,保存这个选手的得分到临时表格中
  608. all_data_temp=self.all_data_df
  609. print(self.all_data_df)
  610. current_player_row=0
  611. #先询问是否计算最终得分,获取输入框信息,计算得分,然后展示出来,展示出来之后将信息保存到临时数据表中
  612. reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '当前选手是否弃权?',QMessageBox.Question)
  613. if reply_one == QMessageBox.Yes:
  614. #选手弃权
  615. judge_number=0
  616. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  617. judge_number=int(all_data_temp.shape[1])-8
  618. else:
  619. judge_number=int(all_data_temp.shape[1])-6
  620. #清空分数框
  621. for show_i in range(1,judge_number+1):
  622. judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  623. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  624. judgeone_score_temp.clear()
  625. #找到第一个未计分的选手
  626. player_row=int(all_data_temp.shape[0])
  627. print("player_row=",player_row)
  628. for player_row_index in range(0,player_row):
  629. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))
  630. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')
  631. 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':
  632. current_player_row=player_row_index
  633. break
  634. current_player_row=player_row_index
  635. self.have_score_number=current_player_row
  636. if self.have_score_number==player_row:
  637. #这时候比赛就提示已经统计完所有选手分数
  638. self.setQMessageBoxoneButtonTextENToCN("提示","已统计完所有选手分数",QMessageBox.Information)
  639. #设置按钮不可点击
  640. self.next_player.setEnabled(False)
  641. #选手弃权按钮
  642. self.player_quit.setEnabled(False)
  643. return
  644. else:
  645. #保存方法在有最高分和没有最高分时有所不同,有
  646. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  647. #将这里面的数据进行覆盖 操作的是save_score_list,score_list_temp_max,score_list_temp_min
  648. for judge_number_index in range(0,judge_number):
  649. print(judge_number_index)
  650. all_data_temp.iloc[current_player_row,judge_number_index+3]=0
  651. all_data_temp.iloc[current_player_row,judge_number_index+4]=0
  652. all_data_temp.iloc[current_player_row,judge_number_index+5]=0
  653. all_data_temp.iloc[current_player_row,judge_number_index+6]=0
  654. else:
  655. for judge_number_index in range(0,judge_number):
  656. all_data_temp.iloc[current_player_row,judge_number_index+3]=0
  657. all_data_temp.iloc[current_player_row,judge_number_index+4]=0
  658. print("弃权后all_data_temp=",all_data_temp)
  659. #重新保存数据表,最后再赋值回去
  660. all_data_temp.to_excel('temp_data/'+str(self.race_name.text())+'_临时存储数据.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引
  661. self.all_data_df=all_data_temp
  662. self.have_score_number=self.have_score_number+1
  663. self.setQMessageBoxoneButtonTextENToCN("提示",str(current_player_row+1)+"号选手"+str(all_data_temp.loc[current_player_row,'选手姓名'])+"弃权成功,马上跳到下一个选手",QMessageBox.Information)
  664. if self.have_score_number==player_row:
  665. #这时候比赛就提示已经统计完所有选手分数
  666. self.setQMessageBoxoneButtonTextENToCN("提示","已统计完所有选手分数",QMessageBox.Information)
  667. self.current_player.setText("本场比赛所有选手已比赛完毕,请退出程序")
  668. #保存方法在有最高分和没有最高分时有所不同,有
  669. #清空分数框
  670. for show_i in range(1,judge_number+1):
  671. judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  672. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  673. judgeone_score_temp.clear()
  674. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  675. #设置最高分
  676. self.judge_com_max.setText("最高分: ")
  677. #设置最低分
  678. self.judge_com_min.setText("最低分: ")
  679. #设置最终分数
  680. self.judge_com_average.setText(str(''))
  681. else:
  682. #设置最终分数
  683. self.judge_com_average.setText(str(''))
  684. self.judgeone_score_1.setFocus() #设置光标
  685. #设置按钮不可点击
  686. self.next_player.setEnabled(False)
  687. #选手弃权按钮
  688. self.player_quit.setEnabled(False)
  689. return
  690. else:
  691. #跳转到下一个选手
  692. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  693. self.current_player.setText("当前选手:"+str(current_player_row+2)+"号选手"+str(all_data_temp.loc[current_player_row+1,'选手姓名']))
  694. #设置最高分
  695. self.judge_com_max.setText("最高分: ")
  696. #设置最低分
  697. self.judge_com_min.setText("最低分: ")
  698. #设置最终分数
  699. self.judge_com_average.setText(str(''))
  700. else:
  701. #设置下一个选手
  702. self.current_player.setText("当前选手:"+str(current_player_row+2)+"号选手"+str(all_data_temp.loc[current_player_row+1,'选手姓名']))
  703. #设置最终分数
  704. self.judge_com_average.setText(str(''))
  705. self.judgeone_score_1.setFocus() #设置光标
  706. return
  707. else:
  708. self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)
  709. return
  710. #结束比赛
  711. def func_exit_race(self):
  712. #获取数据,保存这个选手的得分到临时表格中
  713. all_data_temp=self.all_data_df
  714. print(self.all_data_df)
  715. reply_zero=self.setQMessageappENToCN('提示', '请选择退出程序的原因?',QMessageBox.Question)
  716. if reply_zero == QMessageBox.Yes:
  717. reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否确认选择比赛暂停?',QMessageBox.Question)
  718. if reply_one == QMessageBox.Yes:
  719. self.setQMessageBoxoneButtonTextENToCN("提示","比赛暂停,临时数据保存成功",QMessageBox.Information)
  720. sys.exit(0)
  721. return
  722. else:
  723. self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)
  724. return
  725. return
  726. else:
  727. reply_two=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否确认选择比赛结束?',QMessageBox.Question)
  728. if reply_two == QMessageBox.Yes:
  729. #导出数据,清空临时表
  730. all_data_temp=all_data_temp.sort_values(by=['实得分'],ascending=False) #按照抽签序号排序
  731. all_data_temp=all_data_temp.reset_index(drop=True) #重新排列一下索引
  732. player_row=int(all_data_temp.shape[0])
  733. print("player_row=",player_row)
  734. for player_row_index in range(0,player_row):
  735. all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-2]=player_row_index+1
  736. all_data_temp.to_excel('save_data/'+str(self.race_name.text())+'_最终数据全部备份版.xlsx', sheet_name='部分信息', index=True) # index false为不写入索引
  737. #保留特定数据
  738. all_data_temp_new = all_data_temp[['抽签序号', '选手姓名', '曲目名称','实得分','最终排名']]
  739. # 创建一个新的文档
  740. doc_part=docx.Document()
  741. # 添加标题
  742. para_heading=doc_part.add_heading(str(self.race_name.text()), 5)
  743. para_heading.alignment=docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER#设置为左对齐
  744. # 添加表格
  745. table_part = doc_part.add_table(rows=all_data_temp_new.shape[0]+1, cols=all_data_temp_new.shape[1])
  746. # 添加表头
  747. hdr_cells = table_part.rows[0].cells
  748. for i in range(all_data_temp_new.shape[1]):
  749. hdr_cells[i].text = all_data_temp_new.columns[i]
  750. # 添加每一行数据
  751. for i in range(all_data_temp_new.shape[0]):
  752. row_cells = table_part.rows[i+1].cells
  753. for j in range(all_data_temp_new.shape[1]):
  754. row_cells[j].text = str(all_data_temp_new.values[i,j])
  755. # 保存文件
  756. doc_part.save('save_data/'+str(self.race_name.text())+'_最终数据简洁版.docx')
  757. # del_files("temp_data/")
  758. self.setQMessageBoxoneButtonTextENToCN("提示","最终数据导出成功,本次比赛临时数据已清除",QMessageBox.Information)
  759. sys.exit(0)
  760. return
  761. else:
  762. self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)
  763. return
  764. return
  765. return
  766. #根据文件来读取信息,这个是不一样的,最后写才对,这个继续前次比赛,比赛的信息设置与全新比赛不相同
  767. def func_continue_race(self):
  768. #先是询问是否继续上次比赛
  769. reply_one=self.setQMessageBoxtwoButtonTextENToCN('提示', '是否继续上次比赛?',QMessageBox.Question)
  770. if reply_one == QMessageBox.Yes:
  771. folderName, _ = QFileDialog.getOpenFileName(self, "选择xlsx文件", "", "*.xlsx")
  772. race_name=folderName.split("/")[-1].split("_")[0]
  773. self.race_name.setText(race_name)
  774. self.all_data_df=pd.read_excel('temp_data/'+folderName.split("/")[-1],index_col=0)
  775. all_data_temp=self.all_data_df
  776. #界面展示与隐藏
  777. self.race_prepare.setVisible(False) #初始设置隐藏
  778. self.race_going.setVisible(True) #初始设置隐藏
  779. #设置比赛名称
  780. self.race_going_name.setText(race_name)
  781. #设置选手初值
  782. current_player_row=0
  783. #找到第一个未计分的选手
  784. player_row=int(all_data_temp.shape[0])
  785. print("player_row=",player_row)
  786. for player_row_index in range(0,player_row):
  787. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3]))
  788. print(str(all_data_temp.iloc[player_row_index,int(all_data_temp.shape[1])-3])=='-1')
  789. 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':
  790. current_player_row=player_row_index
  791. break
  792. current_player_row=player_row_index
  793. self.have_score_number=current_player_row
  794. judge_number=0
  795. self.remove_score_number=int(all_data_temp.loc[0,'去掉几个最高分'])
  796. #设置界面信息:当前选手,是否展示实得分最高分,评委名字
  797. if int(all_data_temp.loc[0,'去掉几个最高分'])>0:
  798. self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")
  799. for show_i in range(1,5):
  800. judge_com_label_name="judge_com_label_"+str(show_i)
  801. judge_com_temp = self.race_going.findChild(QLabel,judge_com_label_name)
  802. judge_com_temp.setVisible(True)
  803. #设置最高分
  804. self.judge_com_max.setText("最高分: ")
  805. #设置最低分
  806. self.judge_com_min.setText("最低分: ")
  807. #设置最终分数
  808. self.judge_com_average.setText(str(''))
  809. judge_number=int(all_data_temp.shape[1])-8
  810. else:
  811. #设置下一个选手
  812. self.current_player.setText("当前选手:"+str(current_player_row+1)+"号选手")
  813. self.judge_com_average_label.setVisible(True)
  814. self.judge_com_average.setVisible(True)
  815. #设置最终分数
  816. self.judge_com_average.setText(str(''))
  817. judge_number=int(all_data_temp.shape[1])-6
  818. judge_namelist=[column for column in all_data_temp]
  819. judge_one_namelist=judge_namelist[3:3+judge_number]
  820. for show_i in range(1,judge_number+1):
  821. judge_one_label_name="judge_one_label_"+str(show_i)
  822. judge_one_temp = self.race_going.findChild(QLabel,judge_one_label_name)
  823. #设置评委label的text
  824. judge_one_temp.setText(judge_one_namelist[show_i-1].split(":")[0]+":"+str(show_i)+"号评委")
  825. judge_one_temp.setVisible(True)
  826. judgeone_score_input_name="judgeone_score_input_"+str(show_i)
  827. judgeone_score_temp = self.race_going.findChild(QLineEdit,judgeone_score_input_name)
  828. judgeone_score_temp.setVisible(True)
  829. else:
  830. self.setQMessageBoxoneButtonTextENToCN("提示","用户取消操作",QMessageBox.Information)
  831. return
  832. if __name__ == '__main__':
  833. app=QApplication(sys.argv)
  834. w = MyWindow()
  835. w.ui.show()
  836. app.exec()

程序打包成exe

指令 安装pyinstall库

  1. 文件目录
  2. 根路径
  3. getscore.py
  4. assets
  5. xxx.ui
  6. save_data
  7. temp_data
  8. pyinstaller -F -w getscore.py --add-data ".\\assets\\*;.\\assets"

参考文章

感谢以下作者的知识分享

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

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

原文链接:https://www.cnblogs.com/dongxuelove/p/18296159

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号