from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QPushButton, QVBoxLayout, QMessageBox
from PyQt5.QtWidgets import QLineEdit
class AirlineServiceApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('航空服务查询')
layout = QVBoxLayout()
# 航线选择
self.label_route = QLabel('请选择航线:')
layout.addWidget(self.label_route)
self.route_combo = QComboBox()
self.route_combo.addItems(['中国去欧美', '中国去非欧美', '中国国内'])
layout.addWidget(self.route_combo)
# 舱位选择
self.label_class = QLabel('请选择舱位:')
layout.addWidget(self.label_class)
self.class_combo = QComboBox()
self.class_combo.addItems(['商务舱', '经济舱'])
layout.addWidget(self.class_combo)
# 飞行时间输入
self.label_duration = QLabel('请输入飞行时间(小时):')
layout.addWidget(self.label_duration)
self.duration_edit = QLineEdit()
layout.addWidget(self.duration_edit)
# 查询按钮
self.query_button = QPushButton('查询')
self.query_button.clicked.connect(self.query_service)
layout.addWidget(self.query_button)
# 结果显示
self.result_label = QLabel('结果: ')
layout.addWidget(self.result_label)
self.setLayout(layout)
def query_service(self):
route = self.route_combo.currentText()
seat_class = self.class_combo.currentText()
duration = self.duration_edit.text()
try:
duration = float(duration)
except ValueError:
self.result_label.setText('结果: 飞行时间无效(请输入数字)')
return
# 判断服务
if route == '中国去欧美':
food = '有食物供应'
movie = '可以播放电影'
elif route == '中国去非欧美':
food = '有食物供应'
movie = '可以播放电影' if seat_class == '商务舱' else '不可以播放电影'
elif route == '中国国内':
if seat_class == '商务舱':
food = '有食物供应'
movie = '不可以播放电影'
else: # 经济舱
food = '有食物供应' if duration > 2 else '无食物供应'
movie = '不可以播放电影'
# 显示结果
self.result_label.setText(f'结果: {food}, {movie}')
if __name__ == '__main__':
app = QApplication([])
window = AirlineServiceApp()
window.show()
app.exec_()
浙公网安备 33010602011771号