这段代码有人能帮我打包成exe吗? 求发邮箱1653630690@qq.com,求解决方法
import os
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
import cv2
root = Tk()
root.title('图片RGB修改工具')
root.geometry('300x650')
root.resizable(False,False)
key = False
def bt_0_a():
global files
global img
global key
files = filedialog.askopenfilename(title='选择jpg格式文本文件',
filetypes=(('jpg文件','*.jpg'),))
img = cv2.imread(r'%s'%files)
#img = cv2.cvtColor(img_, cv2.COLOR_BGR2RGB)
_img = img.copy()
key = True
bt_0 = Button(root, padx=20, pady=20, text='载入文件', command=bt_0_a)
bt_0.pack()
label_6 = Label(root, text='输入RGB范围最小值 0-255')
label_6.pack()
label__R = Label(root, text='R')
label__R.pack()
text__1 = Text(root, width=5,height=1)
text__1.pack()
label__G = Label(root, text='G')
label__G.pack()
text__2 = Text(root, width=5,height=1)
text__2.pack()
label__B = Label(root, text='B')
label__B.pack()
text__3 = Text(root, width=5,height=1)
text__3.pack()
label_7 = Label(root, text='输入RGB范围最大值 0-255')
label_7.pack()
label_R = Label(root, text='R')
label_R.pack()
text_1 = Text(root, width=5,height=1)
text_1.pack()
label_G = Label(root, text='G')
label_G.pack()
text_2 = Text(root, width=5,height=1)
text_2.pack()
label_B = Label(root, text='B')
label_B.pack()
text_3 = Text(root, width=5,height=1)
text_3.pack()
label_4 = Label(root, text='改为数值')
label_4.pack()
label_R_ = Label(root, text='R')
label_R_.pack()
text_1_ = Text(root, width=5,height=1)
text_1_.pack()
label_G_ = Label(root, text='G')
label_G_.pack()
text_2_ = Text(root, width=5,height=1)
text_2_.pack()
label_B_ = Label(root, text='B')
label_B_.pack()
text_3_ = Text(root, width=5,height=1)
text_3_.pack()
#file_text = files.read(encoding='utf-8')
##return file_text
def Text_RGB():
global R
global G
global B
global R
global G
global B
global R
global G
global B
R = text__3.get('0.0','end')
G = text__2.get('0.0','end')
B = text__1.get('0.0','end')
R = text_3.get('0.0','end')
G = text_2.get('0.0','end')
B = text_1.get('0.0','end')
R = text_3.get('0.0','end')
G = text_2_.get('0.0','end')
B_ = text_1_.get('0.0','end')
if key == False:
messagebox.showerror('错误','未选取要更改的图片')
if int(R) > 255 or int(G) > 255 or int(B) > 255 or int(_R) > 255 or int(_G) > 255 or int(_B) > 255:
messagebox.showerror('错误','请输入正确的RGB数值')
elif R == '\n' or G == '\n' or B == '\n' or _R == '\n' or _G == '\n' or _B == '\n':
messagebox.showerror('错误','请输入正确的RGB数值')
for i in img:
for j in i:
if (j[0] <= int(R) and j[1] <= int(G) and j[2]<= int(B) and j[0] >= int(R) and j[1] >= int(G) and j[2] >= int(B)):
#满足条件进行像素值更换
j[0] = R
j[1] = G
j[2] = B
bt_1 = Button(root, padx=20, pady=20, text='修改图像', command=Text_RGB)
bt_1.pack()
def save():
cv2.imwrite('%s'%files, img)
bt_3 = Button(root, padx=20, pady=20, text='保存图像', command=save)
bt_3.pack()
root.mainloop()
以前打包过类似程序,手动打包的话需要把那些模块都输入才可以打包成功,但是后来发现个很方便的打包方法。
推荐使用auto-py-to-exe,安装,并且运行他,选择要打包的脚本,设定一下参数就可以很快打包
pip install auto-py-to-exe
安装完成后,直接在命令行运行auto-py-to-exe
然后就可以可视化打包了,并且不会出问题