基于PyQt5的2024年包头市“工匠杯”CAD机械设计比赛抽签系统实现

接上文,在2024年包头市“工匠杯”CAD机械设计比赛中,抽签系统是至关重要的一环。本文将分享一个基于PyQt5框架的抽签系统,实现了抽签模式、中奖模式、分组模式、以及配对模式,能够满足多种比赛场景的需求,并且支持导入名单、开始抽签、停止抽签及导出结果功能。

项目简介

该系统采用Python编程语言,基于PyQt5构建图形用户界面(GUI)。系统支持四种模式:  

1. **抽签模式**:从导入的名单中随机抽取数字。

2. **中奖模式**:从导入的名单中随机抽取若干个获奖者。

3. **分组模式**:将导入的名单随机分配到不同组。

4. **配对模式**:从左右两个名单中随机配对,直到其中一个名单中的人员被配对完毕。

项目功能模块

1. 图形用户界面(GUI)设计

采用PyQt5的`QVBoxLayout`和`QHBoxLayout`布局控件,设计了直观的界面,包括标题、模式切换按钮、操作按钮、结果显示区域和历史记录框。用户可以通过界面轻松切换不同模式,并进行抽签操作。

def initUI(self):

    # 设置主窗口布局

    main_layout = QVBoxLayout()

 

    # 标题

    self.title_label = QLabel("2024 年包头市“工匠杯”CAD 机械设计比赛 抽签系统")

    self.title_label.setStyleSheet("font-size: 24px; font-weight: bold;")

    main_layout.addWidget(self.title_label)

 

    # 模式切换按钮

    mode_layout = QHBoxLayout()

    self.raffle_mode_button = QPushButton("抽签模式")

    self.raffle_mode_button.clicked.connect(self.set_raffle_mode)

    mode_layout.addWidget(self.raffle_mode_button)

 

    self.prize_mode_button = QPushButton("中奖模式")

    self.prize_mode_button.clicked.connect(self.set_prize_mode)

    mode_layout.addWidget(self.prize_mode_button)

 

    self.group_mode_button = QPushButton("分组模式")

    self.group_mode_button.clicked.connect(self.set_group_mode)

    mode_layout.addWidget(self.group_mode_button)

 

    self.pair_mode_button = QPushButton("配对模式")

    self.pair_mode_button.clicked.connect(self.set_pair_mode)

    mode_layout.addWidget(self.pair_mode_button)

 

    main_layout.addLayout(mode_layout)

 

    # 导入、开始、停止按钮

    operation_layout = QHBoxLayout()

    self.load_button = QPushButton("导入名单")

    self.load_button.clicked.connect(self.load_names)

    operation_layout.addWidget(self.load_button)

 

    self.start_button = QPushButton("开始")

    self.start_button.clicked.connect(self.start_action)

    self.start_button.setEnabled(False)

    operation_layout.addWidget(self.start_button)

 

    self.stop_button = QPushButton("停止")

    self.stop_button.clicked.connect(self.stop_action)

    self.stop_button.setEnabled(False)

    operation_layout.addWidget(self.stop_button)

 

    self.export_button = QPushButton("导出结果")

    self.export_button.clicked.connect(self.export_results)

    operation_layout.addWidget(self.export_button)

 

    main_layout.addLayout(operation_layout)

 

    # 显示当前结果的标签

    self.result_label = QLabel("")

    self.result_label.setStyleSheet("font-size: 30px;")

    main_layout.addWidget(self.result_label)

 

    # 历史记录框

    self.history_label = QLabel("历史记录:")

    self.history_label.setStyleSheet("font-size: 18px;")

    main_layout.addWidget(self.history_label)

 

    self.history_listbox = QListWidget()

    main_layout.addWidget(self.history_listbox)

 

    self.setLayout(main_layout)

 

    # 设置初始模式

    self.set_raffle_mode()

```

 2. 模式切换

通过四个按钮切换模式,分别实现不同的抽签逻辑。点击相应的模式按钮后,界面会清空历史记录,并激活/禁用相应的功能按钮。

def set_raffle_mode(self):

    self.mode = "抽签模式"

    self.stop_button.setVisible(True)

    self.result_label.setText("")

    self.history_listbox.clear()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值