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

news/2024/7/10 18:48:09 标签: 开源, python, 数据库

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

源代码

需要安装pyqt5这个库

python"># -*- 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_())

http://www.niftyadmin.cn/n/5055425.html

相关文章

【算法】直接插入排序

文章目录 概念实现过程时间复杂度和空间复杂度代码示例 总结 概念 直接插入排序&#xff08;Insertion Sort&#xff09;是一种简单直观的排序算法&#xff0c;它的基本思想是通过构建有序的子序列&#xff0c;逐步将无序的元素插入到有序序列中&#xff0c;最终实现整体的排序…

WDT实验

#include"exynos_4412.h"void Delay(unsigned int Time) {while(Time--);} int main() {/*设置一级分频*/WDT.WTCON WDT.WTCON &((~0xFF)<<8) | (0x8D<<8);/*设置二级分频*/WDT.WTCON WDT.WTCON | (0x3<<3);/*WTCON 递减频率 &#xff1d; …

ChatGPT Prompting开发实战(十二)

一、如何开发prompts实现个性化的对话方式 通过设置“system”和“user”等roles&#xff0c;可以实现个性化的对话方式&#xff0c;并且可以结合参数“temperature”的设定来差异化LLM的输出内容。在此基础上&#xff0c;通过构建一个餐馆订餐对话机器人来具体演示对话过程。…

【PID控制技术】

PID控制技术 简介控制原理相关术语调参技巧相互作用 相似算法与PWM对比 应用范围优缺点硬件支持 简介 PID控制是一种在工业过程控制中广泛应用的控制策略&#xff0c;其全称是比例-积分-微分&#xff08;Proportional Integral Derivative&#xff09;控制。它的基本原理是根据…

【CAN信号解析】使用python-can/cantools解析CAN数据

文章目录 1. 如何解析CAN消息1.1 简介1.2 python-can库使用2. python-can库介绍2.1 完整解析流程2.2 简单示例3. 总结与坑4. 代码示例1. 解析一个DBC2. 生成一个DBC3. 解析.asc数据 保存为.csv格式4. 根据DBC解析CAN信号 及 解析radar的mf4数据1. 如何解析CAN消息 关于CAN的基…

Mybatis 日志(Apache Commons Logging)

之前我们介绍了使用JDK Log打印Mybatis运行时的日志&#xff1b;本篇我们介绍使用Apache Commons Logging打印Mybatis运行时的日志。 如何您对Mybatis中使用JDK Log不太了解&#xff0c;可以参考&#xff1a; Mybatis 日志(JDK Log)https://blog.csdn.net/m1729339749/articl…

Excel数据丢失怎么找回?详细恢复教程分享!

“我熬了好几个大夜才完成的一份Excel报表不知道为什么有些数据丢失了&#xff0c;现在处理起来很麻烦。有什么方法可以找回丢失的Excel数据吗&#xff1f;快帮帮我&#xff01;” Excel作为一个强大的办公工具&#xff0c;我们在工作中经常都需要用到它。最令人崩溃的事就是有…

柔性数组----动态内存开辟

Hello&#xff0c;大家好&#xff0c;今天分享的是C语言不怎么用的到的柔性数组&#xff0c;虽然说柔性数组我们不怎么用的到&#xff0c;但是它有一些优点&#xff0c;比如和我们动态内存开辟几个函数一起用&#xff0c;它的利用空间的效率特别高&#xff0c;那今天我们就讲一…