如何让pyinstaller导入ttk主题? [英] How to make pyinstaller import the ttk theme?
问题描述
我完成了一个项目,它在下面
I have a project done and it is in the following
import tkinter as tk
from tkinter import ttk
import tkinter.messagebox as tmb
from ttkthemes import ThemedStyle
class UI(ttk.Frame):
def __init__(self, parent=None):
super(UI, self).__init__(parent)
self.parent = parent
style = ThemedStyle(parent)
style.set_theme("arc")
self.parent.geometry("480x520")
self.init_ui()
def init_ui(self):
self.parent.title("Nueva ventana heredada")
self.entrada = ttk.Entry(self, text="ingresa")
self.entrada.grid(row=2, column=2)
boton = ttk.Button(self, text="pulsame", command=self.ver)
boton.grid(row=2, column=3)
self.pack()
def ver(self):
try:
res = int(self.entrada.get())
print(res)
except ValueError:
tmb.showwarning(title = "error", message = " error")
if __name__== '__main__':
root = tk.Tk()
sug = tk.Label(root, text="aqui es para escribir")
sug.pack()
app = UI(parent=root)
app.mainloop()
当我使用pyinstaller创建exe时,释放了导出的exe程序无法执行的错误:下面我留着我用的,需要注意的是我为程序使用了thema怀疑是进口的.
When I use pyinstaller to create an exe, it releases the error that the exported exe program can not be executed: below I leave it as I use it, it should be noted that I have used a thema for the program and I doubt that it is imported.
pyinstaller --windowed ui.py -i icono.ico --onefile
错误
致命错误!无法执行脚本 ui
到类似的网址https://es.stackoverflow.com/questions/118595/como-hacer-que-pyinstaller-importe-el-ttktheme
推荐答案
因为 ttkthemes 似乎对目录做了一些有趣的事情,你可以通过修改规范文件来让它工作.
Because ttkthemes seems to do some funnys with directorys, you can get it to work by modifying the spec file.
从 pyinstaller 为您的应用程序生成一个规范文件,并添加以下内容(根据需要更改站点包的路径)
generate a specfile for your application from pyinstaller, and add the following (changing path to site-packages, as required)
在a= Analysis(.....
将 datas=[],
改为:
data= [('venv\\Lib\\site-packages\\ttkthemes', 'ttkthemes')],
并将 ttkthemes 添加到 hiddenimports
and add ttkthemes to hiddenimports
hiddenimports=['ttkthemes'],
这似乎对我有用
这篇关于如何让pyinstaller导入ttk主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!