I have the following question for Python 3.8.8. I have the following file called test2.py (I know the names of my files aren't great, sorry for that):
# test2.py
from tkinter import *
from tkinter import ttk
window = Tk()
tab_control = ttk.Notebook(window)
tab1 = ttk.Frame(tab_control)
tab2 = ttk.Frame(tab_control)
tab_control.add(tab1, text='First tab')
tab_control.add(tab2, text='Second tab')
lbl1 = Label(tab1, text= 'First label')
lbl1.grid(column=0, row=0)
lbl2 = Label(tab2, text= 'Second label')
lbl2.grid(column=0, row=0)
tab_control.pack(expand=1, fill='both')
window.mainloop()
This code works just fine and if I type pyinstaller --onefile --noconsole test2.py
the output is as expected (a working standalone file).
However, I now change my test2.py code to:
# test2.py
from tkinter import *
from tkinter import ttk
from test import *
window = Tk()
tab_control = ttk.Notebook(window)
tab1 = ttk.Frame(tab_control)
tab2 = ttk.Frame(tab_control)
tab_control.add(tab1, text='First tab')
tab_control.add(tab2, text='Second tab')
lbl1 = Label(tab1, text= text1)
lbl1.grid(column=0, row=0)
lbl2 = Label(tab2, text= text2)
lbl2.grid(column=0, row=0)
tab_control.pack(expand=1, fill='both')
window.mainloop()
where test.py (again not a great name, sorry) is in the same folder as test2.py and reads:
# test.py
text1 = 'First label'
text2 = 'Second label'
When I execute test2.py in my terminal it works perfectly, but pyinstaller --onefile --noconsole test2.py
now gives a corrupt file (it is being generated, but when I try to execute it I get an error message saying "Fatal error detected" as title and "Failed to execute script test2" as message). Can somebody help me with this? Many thanks in advance!
On another note, how could I fix this problem if test.py was in a subfolder? So for example test2.py is in a folder called Downloads, and test.py is in a folder called Subfunctions which is in turn a folder in Downloads. Again many thanks!