Tkinter实现GUI

from tkinter import *
import tkinter.filedialog

root = Tk()
root.geometry("800x800")

# 设置窗口标题
root.title('裂痕检测系统')

text1 = StringVar()
text1.set("模型路径:") #可变的Lable内容

def loadmodel():  #按钮的动作
    path = tkinter.filedialog.askopenfilename()
    text1.set("模型路径:"+path)
    global model
    model = load_model(path)

def loadimage():  #加载图片,并通过画布canvas实现覆盖
    global show
    select_file = tkinter.filedialog.askopenfilename()
    text2.set("图片路径:"+select_file)
    #e.set(select_file)
    load = Image.open(select_file)
    load = load.resize((227,227))
    show = ImageTk.PhotoImage(load)

    cv.create_image((227,227), image = show)
    cv.pack()

button1 = tkinter.Button(root, text ="load_model", command = loadmodel, font=("幼圆", 20))   #command链接按钮动作
button1.pack()

label1 = tkinter.Label(root,textvariable = text1, font=("幼圆", 20)) #textvariable动态的lable文本
label1.pack()

cv = Canvas(root)
cv.pack()

root.mainloop()

Pyinstall实现打包

! pyinstaller -F --hidden-import=numpy.core._dtype_ctypes --additional-hooks-dir=hooks crack_detect_GUI.py -p C:\aa

**pyinstall输入参数的含义
-F 表示生成单个可执行文件
-w 表示去掉控制台窗口,这在GUI界面时非常有用。不过如果是命令行程序的话那就把这个选项删除吧!
-p 表示你自己自定义需要加载的类路径,一般情况下用不到
-i 表示可执行文件的图标**

  • ModuleNotFoundError: No module named 'tensorflow_core.python。解决方法:运行报错是pyinstaller无法导入tensorflow_core,在所运行的python文件(mypython.py中使用from tensorflow import *)路径下创建一个名为hooks的文件夹,文件夹没创建python程序文件hook-tensorflow.py(https://blog.csdn.net/TaChean...
  • ModuleNotFoundError: No module named ’numpy.core.__dtype_ctypes’ 。解决方法:--hidden-import=numpy.core._dtype_ctype
  • Cannot find existing PyQt5 plugin directories。解决方法:因为用户名是中文, pyinstaller 字符出现乱码导致找不到。把目标路径的PyQt复制一份到全英文目录, 然后使用-p 指定该目录。(https://blog.csdn.net/qq_3981...

anie
4 声望0 粉丝

引用和评论

0 条评论