吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2324|回复: 17
收起左侧

[Python 原创] Python - ico文件转换器 - 图片格式转图标

  [复制链接]
TZ425 发表于 2023-11-2 03:22
本帖最后由 TZ425 于 2023-11-2 03:23 编辑

软件功能:
当打包程序需要用到图标时,可以使用本程序将png、jpeg、jpg等图片格式转换
为ico图标格式。(不适合大文件转换....这个问题目前还在解决!)


以下是成品链接和源码:
ico图标转换器
[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
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
import tkinter as tk
from tkinter import filedialog
from PIL import Image
from tkinter import messagebox
from tkinter import ttk
import os
 
# 创建窗口
window = tk.Tk()
window.title("ico转换器")
window.geometry("250x150")
 
# 创建Notebook小部件
notebook = ttk.Notebook(window)
notebook.pack(fill=tk.BOTH, expand=True)
 
# 第一页 - 选择文件页面
select_file_frame = tk.Frame(notebook)
notebook.add(select_file_frame, text="  选择目标文件  ")
 
target_label = tk.Label(select_file_frame, text="目标文件:")
target_label.pack()
target_entry = tk.Entry(select_file_frame)
target_entry.pack()
 
def select_file():
    filepath = filedialog.askopenfilename(filetypes=[("文件:", "*.jpg;*.jpeg;*.png;")])
    target_entry.delete(0, tk.END)
    target_entry.insert(0, filepath)
 
file_btn = tk.Button(select_file_frame, text="选择文件", command=select_file)
file_btn.pack()
 
# 第二页 - 选择路径页面
select_path_frame = tk.Frame(notebook)
notebook.add(select_path_frame, text="  选择保存路径  ")
 
save_label = tk.Label(select_path_frame, text="保存到:")
save_label.pack()
save_entry = tk.Entry(select_path_frame)
save_entry.pack()
 
def select_path():
    path = filedialog.askdirectory()
    save_entry.delete(0, tk.END)
    save_entry.insert(0, path)
 
path_btn = tk.Button(select_path_frame, text="选择路径", command=select_path)
path_btn.pack()
 
# 定义图片转换为ICO函数
def convert_to_ico():
    target_file = target_entry.get()
    save_path = save_entry.get()
 
    try:
        img = Image.open(target_file)
        filename = os.path.splitext(os.path.basename(target_file))[0]
        img.save(save_path + "/" + filename + ".ico", format="ICO")
        messagebox.showinfo("转换完成", "图片已成功转换为ICO文件!")
    except Exception as e:
        messagebox.showerror("转换失败,文件不正确或者路径不正确", str(e))
 
# 创建转换按钮
convert_btn = tk.Button(window, text="开始转换", command=convert_to_ico)
convert_btn.pack()
 
# 运行窗口
window.mainloop()

程序运行效果

程序运行效果

免费评分

参与人数 5吾爱币 +9 热心值 +4 收起 理由
快乐的小驹 + 1 谢谢@Thanks!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
ShoreNinth + 1 谢谢@Thanks!
cxx0515 + 1 + 1 用心讨论,共获提升!
DarkOps + 1 我很赞同!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| TZ425 发表于 2023-11-2 09:06
Kls673M 发表于 2023-11-2 08:51
感谢分享,如果需要自定义图标不是应该在打包时就设定好吗?

是的,这是打包时添加图标的语法:pyinstaller -F -w -i 图标.ico python文件.py
不添加图标:pyinstaller -F -w python文件.py
sai609 发表于 2023-11-2 08:33
头像被屏蔽
KMT-jiang 发表于 2023-11-2 08:36
Kls673M 发表于 2023-11-2 08:51
感谢分享,如果需要自定义图标不是应该在打包时就设定好吗?
zeal_nba 发表于 2023-11-2 10:06
谢谢分享,又认识了窗口库与函数,还有转换图片的方法,很实用,很受用
lry123 发表于 2023-11-2 10:22
感谢大佬分享 谢谢
xiaoyaowolf 发表于 2023-11-2 10:25
感谢分享,留个标,学习一下
likezqc 发表于 2023-11-2 10:27

感谢分享,留个标,学习一下
Bean2012 发表于 2023-11-2 11:16
Python办公自动化,奈斯
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-30 23:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表