pyside6开发第一个图片转换图标程序

myjgptoico.py 这个是一个UI转换过来的文件,命名不太规范。

#myjgptoico.py
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'myjgptoico.ui'
##
## Created by: Qt User Interface Compiler version 6.1.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import *  # type: ignore
from PySide6.QtGui import *  # type: ignore
from PySide6.QtWidgets import *  # type: ignore


class Ui_Form(object):
    def setupUi(self, Form):
        if not Form.objectName():
            Form.setObjectName(u"Form")
        Form.resize(542, 441)
        self.widget = QWidget(Form)
        self.widget.setObjectName(u"widget")
        self.widget.setGeometry(QRect(150, 90, 258, 225))
        self.verticalLayout = QVBoxLayout(self.widget)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.pushButton = QPushButton(self.widget)
        self.pushButton.setObjectName(u"pushButton")

        self.verticalLayout.addWidget(self.pushButton)

        self.label = QLabel(self.widget)
        self.label.setObjectName(u"label")

        self.verticalLayout.addWidget(self.label, 0, Qt.AlignHCenter)


        self.retranslateUi(Form)

        QMetaObject.connectSlotsByName(Form)
    # setupUi

    def retranslateUi(self, Form):
        Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None))
        self.pushButton.setText(QCoreApplication.translate("Form", u"\u6587\u4ef6\u9009\u62e9", None))
#if QT_CONFIG(whatsthis)
        self.label.setWhatsThis(QCoreApplication.translate("Form", u"<html><head/><body><p>\u8fd9\u662f\u4ec0\u4e48</p></body></html>", None))
#endif // QT_CONFIG(whatsthis)
        self.label.setText(QCoreApplication.translate("Form", u"\u8fd9\u91cc\u8f93\u51fa\u6587\u4ef6\u8def\u5f84", None))
    # retranslateUi



#JPG2ICO copy.py
# from PyQt5.Qt import *
from PySide6.QtWidgets import QApplication, QMainWindow, QFileDialog,QWidget,QPushButton, QLabel

import sys , os
from PySide6.QtCore import Slot

from myjgptoico import *

@Slot()
def say_hello():
 print("Button clicked, Hello!")



class MyWindow(QMainWindow, Ui_Form):

    def __init__(self, parent=None):
        # 继承自己设计的Ui界面
        super(MyWindow, self).__init__(parent)
        self.setupUi(self)
        # 调用自己的函数补充ui界面
        # self.initUi()
        self.setWindowTitle(QCoreApplication.translate("Form", u"QFileDialog文件选择对话框 - 图片转ico图标工具 by chunk", None))
        # QMainWindow.setObjectName(u"QFileDialog文件选择对话框 - 图片转ico图标工具 by chunk")
        self.pushButton.clicked.connect(self.print_filename)

    
    def print_filename(self):
        FileDialog = QFileDialog(self, '文件选择', './', 'jpg(*.jpg *.jpeg);;png(*.png);;python(*.py)')
        FileDialog.setAcceptMode(QFileDialog.AcceptOpen)
        FileDirectory = FileDialog.getOpenFileNames(FileDialog,'请选择你要处理的图片','./', 'jpg(*.jpg *.jpeg);;png(*.png);;python(*.py)')
        # print(f"{FileDirectory}")     
        # print(list(FileDirectory[0]))
        FileDirectory = str(FileDirectory[0])
        FileName = FileDirectory.replace('[','').replace(']','').replace('\'','')
        self.label.setText(FileName)
        fname,fename = os.path.splitext(FileName)
        fname = fname + '.ico'
        from jpg2ico import jpg_to_ico
        # print(str(os.path.splitext(FileName)) + 'ico666')
        jpg_to_ico(FileName,fname)



# Create the Qt Application
app = QApplication(sys.argv)
# Create a button, connect it and show it
# button = QPushButton("Click me")
# button.move(200, 200)
# button.setText('打开对话框')
# button.resize(100, 30)
# button.clicked.connect(say_hello)
# button.show()
myWin = MyWindow()
# 展示界面
myWin.show()
# Run the main Qt loop
app.exec()

打开文件选择,选择需要转换的图片就可以转换为ico了。
这次是续这上次的python脚本套上了pyqt外壳GUI。

基本思路是:

  1. 使用pyqt设计器设计UI
  2. 转换UI文件为py脚本
  3. 主脚本导入UI py的脚本模块

选择文件
python3把jpg png图片转换为ico图标

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

少陽君

谢谢老板的拿铁

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值