1

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()

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

error

Fatal Error! Failed to execute script ui

to similar url https://es.stackoverflow.com/questions/118595/como-hacer-que-pyinstaller-importe-el-ttktheme

2 Answers2

2

Because ttkthemes seems to do some funnys with directorys, you can get it to work by modifying the spec file.

generate a specfile for your application from pyinstaller, and add the following (changing path to site-packages, as required)

In the a= Analysis(..... change datas=[],to:

data= [('venv\\Lib\\site-packages\\ttkthemes', 'ttkthemes')],

and add ttkthemes to hiddenimports

hiddenimports=['ttkthemes'],

This then appears to work for me

Chris
  • 29
  • 2
1

The code worked for me fine.. Looks like you haven't successfully imported ttkthemes i.e. it's not properly installed. Therefore, you should do it again. To install ttkthemes (assuming you already have python3 and setup tools):

sudo apt-get install python3-tk
sudo -H pip3 install ttkthemes

This should work perfectly fine.

Eshita Shukla
  • 791
  • 1
  • 8
  • 30