import sysfrom PyQt6.QtWidgets import ( QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QLineEdit, QFileDialog, QProgressBar, QTableWidget, QTableWidgetItem, QHeaderView, QGroupBox, QSplitter, QStatusBar)from PyQt6.QtCore import Qtfrom PyQt6.QtGui import QFont, QColorclass MainWindow(QMainWindow): def __init__(self): super().__init__() self.init_ui() def init_ui(self): """初始化UI""" self.setWindowTitle("调用baiduocr大模型api批量识别磅单(欢迎关注微信公众号:码海听潮)") self.setMinimumSize(800, 700) # 设置全局样式 self.setStyleSheet(""" QMainWindow { background-color: #f5f6fa; } QGroupBox { font-weight: bold; border: 2px solid #dcdde1; border-radius: 8px; margin-top: 10px; padding-top: 10px; background-color: white; } QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 5px 0 5px; color: #273c75; } QPushButton { background-color: #273c75; color: white; border: none; padding: 10px 20px; border-radius: 5px; font-weight: bold; min-width: 100px; } QPushButton:hover { background-color: #192a56; } QPushButton:disabled { background-color: #7f8c8d; } QPushButton#danger { background-color: #c23616; } QPushButton#danger:hover { background-color: #962d22; } QPushButton#success { background-color: #44bd32; } QPushButton#success:hover { background-color: #2e7d32; } QLineEdit { padding: 8px; border: 1px solid #dcdde1; border-radius: 5px; background-color: white; } QLineEdit:focus { border: 2px solid #273c75; } QTableWidget { border: 1px solid #dcdde1; border-radius: 5px; background-color: white; gridline-color: #dcdde1; } QTableWidget::item { padding: 5px; } QTableWidget::item:selected { background-color: #273c75; color: white; } QHeaderView::section { background-color: #273c75; color: white; padding: 8px; border: none; font-weight: bold; } QProgressBar { border: 1px solid #dcdde1; border-radius: 5px; text-align: center; background-color: white; height: 20px; } QProgressBar::chunk { background-color: #44bd32; border-radius: 5px; } QStatusBar { background-color: #273c75; color: white; } """) # 创建中央部件 central_widget = QWidget() self.setCentralWidget(central_widget) # 主布局 main_layout = QVBoxLayout(central_widget) main_layout.setSpacing(10) main_layout.setContentsMargins(15, 15, 15, 15) # 创建分割器 splitter = QSplitter(Qt.Orientation.Vertical) main_layout.addWidget(splitter) # 上部控制区域 top_widget = QWidget() top_layout = QVBoxLayout(top_widget) splitter.addWidget(top_widget) # 文件选择区域 file_group = QGroupBox("文件选择") file_layout = QHBoxLayout(file_group) self.path_edit = QLineEdit() self.path_edit.setPlaceholderText("请选择图片目录...") self.browse_btn = QPushButton("浏览目录") file_layout.addWidget(self.path_edit) file_layout.addWidget(self.browse_btn) top_layout.addWidget(file_group) # API设置区域 api_group = QGroupBox("API设置") api_layout = QHBoxLayout(api_group) api_layout.addWidget(QLabel("API Key:")) self.api_key_edit = QLineEdit() self.api_key_edit.setPlaceholderText("请输入API Key") api_layout.addWidget(self.api_key_edit) api_layout.addWidget(QLabel("Secret Key:")) self.secret_key_edit = QLineEdit() self.secret_key_edit.setPlaceholderText("请输入Secret Key") api_layout.addWidget(self.secret_key_edit) self.save_api_btn = QPushButton("保存设置") api_layout.addWidget(self.save_api_btn) top_layout.addWidget(api_group) # 进度区域 progress_group = QGroupBox("处理进度") progress_layout = QVBoxLayout(progress_group) self.progress_bar = QProgressBar() progress_layout.addWidget(self.progress_bar) self.status_label = QLabel("就绪") self.status_label.setStyleSheet("color: #7f8c8d;") progress_layout.addWidget(self.status_label) top_layout.addWidget(progress_group) # 按钮区域(居中显示) button_layout = QHBoxLayout() button_layout.setAlignment(Qt.AlignmentFlag.AlignCenter) self.start_btn = QPushButton("开始识别") self.start_btn.setObjectName("success") self.start_btn.setEnabled(False) self.stop_btn = QPushButton("取消识别") self.stop_btn.setObjectName("danger") self.stop_btn.setEnabled(False) self.export_btn = QPushButton("导出Excel") button_layout.addWidget(self.start_btn) button_layout.addWidget(self.stop_btn) button_layout.addWidget(self.export_btn) top_layout.addLayout(button_layout) # 下部结果表格 bottom_widget = QWidget() bottom_layout = QVBoxLayout(bottom_widget) splitter.addWidget(bottom_widget) result_group = QGroupBox("识别结果") result_layout = QVBoxLayout(result_group) # 创建表格 self.table = QTableWidget() self.table.setColumnCount(9) self.table.setHorizontalHeaderLabels([ '文件名', '车牌号', '打印时间', '毛重', '皮重', '净重', '发货单位', '收货单位', '送货单号' ]) # 设置表格列宽平均分布 header = self.table.horizontalHeader() for i in range(9): header.setSectionResizeMode(i, QHeaderView.ResizeMode.Stretch) result_layout.addWidget(self.table) bottom_layout.addWidget(result_group) # 设置分割器比例 splitter.setSizes([350, 350]) # 状态栏 self.status_bar = QStatusBar() self.setStatusBar(self.status_bar) self.status_bar.showMessage("就绪")def main(): app = QApplication(sys.argv) # 设置应用程序字体 font = QFont("微软雅黑", 9) app.setFont(font) # 创建并显示主窗口 window = MainWindow() window.show() sys.exit(app.exec())if __name__ == "__main__": main()