• 开源python双屏图片浏览器软件


    在这里插入图片描述
    在这里插入图片描述

    源代码

    需要安装pyqt5这个库

    # -*- coding: utf-8 -*-
    
    from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QVBoxLayout, QPushButton, QFileDialog, QAction, QSlider, QHBoxLayout, QWidget
    from PyQt5.QtGui import QPixmap
    from PyQt5.QtCore import Qt, QSize
    import sys
    import os
    
    
    class ImageViewer(QMainWindow):
        def __init__(self):
            super().__init__()
    
            self.setWindowTitle("图片浏览器")
            self.setGeometry(100, 100, 800, 400)
    
            self.image_label_1 = QLabel(self)
            self.image_label_1.setAlignment(Qt.AlignCenter)
            self.image_name_label_1 = QLabel(self)
            self.image_name_label_1.setAlignment(Qt.AlignCenter)
    
            self.image_label_2 = QLabel(self)
            self.image_label_2.setAlignment(Qt.AlignCenter)
            self.image_name_label_2 = QLabel(self)
            self.image_name_label_2.setAlignment(Qt.AlignCenter)
    
            self.slider = QSlider(Qt.Horizontal, self)
            self.slider.valueChanged.connect(self.slider_value_changed)
    
            self.current_index = 0
            self.image_paths = []
    
            layout = QHBoxLayout()
            layout_1 = QVBoxLayout()
            layout_1.addWidget(self.image_label_1)
            layout_1.addWidget(self.image_name_label_1)
            layout_2 = QVBoxLayout()
            layout_2.addWidget(self.image_label_2)
            layout_2.addWidget(self.image_name_label_2)
            layout.addLayout(layout_1)
            layout.addLayout(layout_2)
    
            vbox = QVBoxLayout()
            vbox.addLayout(layout)
            vbox.addWidget(self.slider)
    
            central_widget = QWidget(self)
            central_widget.setLayout(vbox)
            self.setCentralWidget(central_widget)
    
            self.create_menu()
            self.load_images()
    
        def create_menu(self):
            open_folder_action = QAction("打开文件夹", self)
            open_folder_action.triggered.connect(self.open_folder)
    
            menubar = self.menuBar()
            file_menu = menubar.addMenu("文件")
            file_menu.addAction(open_folder_action)
    
        def open_folder(self):
            folder_dialog = QFileDialog.getExistingDirectory(self, "选择文件夹")
            if folder_dialog:
                self.image_paths = self.get_image_files(folder_dialog)
                if self.image_paths:
                    self.current_index = 0
                    self.load_images()
    
        def get_image_files(self, folder_path):
            image_files = []
            for file_name in os.listdir(folder_path):
                if file_name.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp')):
                    image_files.append(os.path.join(folder_path, file_name))
            return image_files
    
        def load_images(self):
            if self.image_paths:
                if self.current_index < len(self.image_paths):
                    image_path_1 = self.image_paths[self.current_index]
                    pixmap_1 = QPixmap(image_path_1)
                    self.image_label_1.setPixmap(
                        pixmap_1.scaled(QSize(300, 300), aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio))
                    self.image_name_label_1.setText(os.path.basename(image_path_1))
                else:
                    self.image_label_1.clear()
                    self.image_name_label_1.clear()
    
                if self.current_index + 1 < len(self.image_paths):
                    image_path_2 = self.image_paths[self.current_index + 1]
                    pixmap_2 = QPixmap(image_path_2)
                    self.image_label_2.setPixmap(
                        pixmap_2.scaled(QSize(300, 300), aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio))
                    self.image_name_label_2.setText(os.path.basename(image_path_2))
                else:
                    self.image_label_2.clear()
                    self.image_name_label_2.clear()
    
                self.slider.setMinimum(0)
                self.slider.setMaximum(len(self.image_paths) - 1)
                self.slider.setValue(self.current_index)
    
        def slider_value_changed(self, value):
            self.current_index = value
            self.load_images()
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        viewer = ImageViewer()
        viewer.show()
        sys.exit(app.exec_())
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
  • 相关阅读:
    智能自动化输送分拣集成设备|快递自动分拣设备厂家告诉您如何提高10倍分拣效率
    OpenGL环境搭建
    版本管理 | 如何解决SVN的合并冲突与分支问题?
    jQuery_按键变色/keyCode/text
    力扣(LeetCode)18. 四数之和(C++)
    CleanMyMac是什么软件?有哪些特色功能?
    Day9-[KMP]难不倒我
    python调用函数详解
    MySQL数据库的增删改查(进阶)
    LeetCode 216 Java 实现
  • 原文地址:https://blog.csdn.net/weixin_43958308/article/details/133377663