UltraDebug

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: A C D R G Y M Z X S P
公益项目,接受捐赠
查看: 1866|回复: 1
收起左侧

[原创工具] 分辨率计算器

[复制链接]
Honeys

主题

0

回帖

UD

新手上路

UID
42
积分
34
注册时间
2022-5-15
最后登录
1970-1-1
2024-2-26 02:28:34 | 显示全部楼层 |阅读模式
最近经常要切照片,写了个分辨率计算器,可以按原图比例计算需要的比例,但是打包运行后出现了错误提示,我代码里没用用过png图片啊?
我的环境是windows10,PY3.12

请朋友们帮忙看看什么原因:
分辨率计算器 - Honeys_UltraDebug

分辨率计算器 - Honeys_UltraDebug

[Python] 纯文本查看 复制代码
import tkinter as tk
from tkinter import ttk
 
def calculate_new_dimension():
    # 根据选择或输入获取原始分辨率
    if selected_option.get() == 'custom':
        original_width = float(original_width_entry.get())
        original_height = float(original_height_entry.get())
    else:
        ratio = selected_option.get().split(':')
        original_width, original_height = float(ratio[0]), float(ratio[1])
     
    # 获取新宽度和新高度的输入
    new_width = new_width_entry.get()
    new_height = new_height_entry.get()
 
    # 如果新宽度有输入,则计算新高度
    if new_width:
        new_width = float(new_width)
        calculated_height = (new_width / original_width) * original_height
        new_height_entry.delete(0, tk.END)
        new_height_entry.insert(0, str(round(calculated_height)))
    # 如果新高度有输入,则计算新宽度
    elif new_height:
        new_height = float(new_height)
        calculated_width = (new_height / original_height) * original_width
        new_width_entry.delete(0, tk.END)
        new_width_entry.insert(0, str(round(calculated_width)))
 
def update_entry_state():
    # 当选择快捷选项时,清空原始分辨率输入区的内容
    if selected_option.get() != 'custom':
        original_width_entry.delete(0, tk.END)
        original_height_entry.delete(0, tk.END)
    # 根据选择启用或禁用原始分辨率输入框
    state = 'normal' if selected_option.get() == 'custom' else 'disabled'
    original_width_entry.config(state=state)
    original_height_entry.config(state=state)
 
# 创建主窗口
root = tk.Tk()
root.title("分辨率计算器 V1.0")
 
# 设置样式
style = ttk.Style()
style.configure('TLabel', font=('Arial', 10))
style.configure('TButton', font=('Arial', 10))
style.configure('TRadiobutton', font=('Arial', 10))
 
# 设置整体布局的内边距
content_frame = ttk.Frame(root, padding="10 10 10 10")  # 上下左右的内边距
content_frame.grid(column=0, row=0, sticky=('N', 'W', 'E', 'S'))
content_frame.columnconfigure(0, weight=1)
content_frame.rowconfigure(0, weight=1)
 
# 软件名字标签
title_label = ttk.Label(content_frame, text="分辨率计算器V1.0", font=('Arial', 12, 'bold'))
title_label.grid(column=0, row=0, columnspan=4, pady=(10, 20))
 
# 快捷选择区域
selected_option = tk.StringVar(value='custom')
options_frame = ttk.Frame(content_frame)
options_frame.grid(column=0, row=1, columnspan=4, sticky='ew')
options = {'custom': '手动', '4:3': '4:3', '16:9': '16:9', '9:16': '9:16'}
for value, text in options.items():
    radio_button = ttk.Radiobutton(options_frame, text=text, value=value, variable=selected_option, command=update_entry_state)
    radio_button.pack(side='left', expand=True)
 
# 原始分辨率输入区
ttk.Label(content_frame, text="原始宽度").grid(column=0, row=2, sticky='w')
original_width_entry = ttk.Entry(content_frame)
original_width_entry.grid(column=1, row=2, sticky='ew', columnspan=3)
ttk.Label(content_frame, text="原始高度").grid(column=0, row=3, sticky='w')
original_height_entry = ttk.Entry(content_frame)
original_height_entry.grid(column=1, row=3, sticky='ew', columnspan=3)
 
# 分隔线
separator = ttk.Separator(content_frame, orient='horizontal')
separator.grid(column=0, row=4, columnspan=4, sticky='ew', pady=10)
 
# 新分辨率输入区
ttk.Label(content_frame, text="新宽度").grid(column=0, row=5, sticky='w')
new_width_entry = ttk.Entry(content_frame)
new_width_entry.grid(column=1, row=5, sticky='ew', columnspan=3)
ttk.Label(content_frame, text="新高度").grid(column=0, row=6, sticky='w')
new_height_entry = ttk.Entry(content_frame)
new_height_entry.grid(column=1, row=6, sticky='ew', columnspan=3)
 
# 计算按钮
calculate_button = ttk.Button(content_frame, text="开始生成", command=calculate_new_dimension)
calculate_button.grid(column=0, row=7, columnspan=4, pady=(10, 5))
 
# 作者名字标签
author_label = ttk.Label(content_frame, text="By: icescat 2024.2.25", foreground="grey", font=('Arial', 7))
author_label.grid(column=0, row=8, columnspan=4, pady=(0, 5))
 
root.mainloop()
SyntaxHighlighter Copyright 2004-2013 Alex Gorbatchev.

分辨率计算器.exe

9.84 MB, 下载次数: 0, 下载积分: UD -2

UltraDebug免责声明
✅以上内容均来自网友转发或原创,如存在侵权请发送到站方邮件9003554@qq.com处理。
✅The above content is forwarded or original by netizens. If there is infringement, please send the email to the destination 9003554@qq.com handle.
回复 打印

使用道具 举报

keyishiyong

主题

0

回帖

UD

新手上路

UID
46
积分
28
注册时间
2022-5-18
最后登录
1970-1-1
2024-2-29 07:28:21 | 显示全部楼层
这个很有用,可以下载收藏
回复 打印

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|站点地图|UltraDebug ( 滇ICP备2022002049号-2 滇公网安备 53032102000034号)

GMT+8, 2025-6-16 18:42 , Processed in 0.032299 second(s), 13 queries , Redis On.

Powered by Discuz X3.4

© 2001-2023 Discuz! Team.

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