Mar-19-2018, 08:40 AM
Hi, I created .exe file from my .py file with cx_Freeze. Exe file created successfully, but now, when I want to run file, only command window opens in a moment and closes. So how can I solve this problem?
This is my app.py.
This is my app.py.
import os
import subprocess
from tkinter import *
from tkinter import messagebox
class Dict(object):
def __init__(self, idx: int, name: str, pdf: str, txt: str, n: int):
self.id = int(idx)
self.name = name
self.pdf = pdf
self.txt = txt
self.n = int(n)
def __repr__(self):
return f'Dict: {self.id}; {self.name}; {self.pdf}; {self.txt}; {self.n}'
class Application(object):
def __init__(self):
# default pdf reader's path
self.reader = self.adobe_reader_exe()
self.dicts = []
self.page = 1
super().__init__()
def adobe_reader_exe(self, path: str='Program Files (x86)') -> str:
# name of 32 bit Adobe Reader executable
acro_exe = 'AcroRd32.exe'
# scan program files folder
for root, dirs, files in os.walk(os.path.join('c:\\', path)):
if acro_exe in files:
return os.path.join(root, acro_exe)
# try to search in 64 bit executable
return None
def adobe_open_pdf(self, filepath: str, page: int=1):
subprocess.Popen([self.reader, '/A', f'page={page}', filepath])
def import_dicts(self):
with open("Dict_list.txt", "r", encoding="utf-8-sig") as fd:
for record in fd:
self.dicts.append(Dict(*record.split('; ')))
def find_page(self, dt, word: str) -> int:
with open(dt.txt, encoding="utf-8-sig" ) as file:
dic = [line.rstrip( '\n' ) for line in file]
word = word.get()
word = word.title()
i = 0
while i < (len( dic ) - 1):
if word >= dic[i] and word < dic[i + 1]:
self.page = i + dt.n
return self.page
i += 1
return False
def run(self):
self.import_dicts()
root = Tk()
root.title( "ԵԳԻ" )
root.configure( background="#83d0c9" )
root.iconbitmap( 'logo.ico' )
text = Label( root, bg="#83d0c9", text="Մուտքագրեք բառը: " ).grid(
row=1, pady=5 )
word = Entry( root )
word.grid( row=2, pady=5 )
word.focus_set()
text = Label( root, bg="#83d0c9",
text="Ընտրեք բառարանը, որում ցանկանում եք փնտրել բառը․" )\
.grid(row=3, pady=5 )
for dct in self.dicts:
row = 3 + dct.id
btn = Button(root, wraplength=700, width=100, text=dct.name,
anchor=W, bg="#009688", command=lambda a=dct:
self.adobe_open_pdf(a.pdf, self.find_page(a, word)))
btn.grid(row=row, pady=3, padx=5)
root.geometry("750x500")
root.mainloop()
if __name__ == '__main__':
try:
app = Application()
app.run()
except KeyboardInterrupt:
print('Exiting application...')and this is my setup.pyfrom cx_Freeze import setup, Executable
setup(name='IGS_Library', version='0.1', executables=[Executable("app.py")])
